Skip to content

Commit 0086b6f

Browse files
committed
Make getResultAsync timeout not counted per history page (#483)
1 parent cdd9308 commit 0086b6f

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/main/java/com/uber/cadence/internal/common/WorkflowExecutionUtils.java

+10-4
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public static byte[] getWorkflowExecutionResult(
125125
TimeUnit unit)
126126
throws TimeoutException, CancellationException, WorkflowExecutionFailedException,
127127
WorkflowTerminatedException, WorkflowTimedOutException, EntityNotExistsError {
128-
// getIntanceCloseEvent waits for workflow completion including new runs.
128+
// getInstanceCloseEvent waits for workflow completion including new runs.
129129
HistoryEvent closeEvent =
130130
getInstanceCloseEvent(service, domain, workflowExecution, timeout, unit);
131131
return getResultFromCloseEvent(workflowExecution, workflowType, closeEvent);
@@ -294,7 +294,8 @@ private static CompletableFuture<HistoryEvent> getInstanceCloseEventAsync(
294294
getWorkflowExecutionHistoryAsync(service, request);
295295
return response.thenComposeAsync(
296296
(r) -> {
297-
if (timeout != 0 && System.currentTimeMillis() - start > unit.toMillis(timeout)) {
297+
long elapsedTime = System.currentTimeMillis() - start;
298+
if (timeout != 0 && elapsedTime > unit.toMillis(timeout)) {
298299
throw CheckedExceptionWrapper.wrap(
299300
new TimeoutException(
300301
"WorkflowId="
@@ -310,7 +311,7 @@ private static CompletableFuture<HistoryEvent> getInstanceCloseEventAsync(
310311
if (history == null || history.getEvents().size() == 0) {
311312
// Empty poll returned
312313
return getInstanceCloseEventAsync(
313-
service, domain, workflowExecution, pageToken, timeout, unit);
314+
service, domain, workflowExecution, pageToken, timeout - elapsedTime, unit);
314315
}
315316
HistoryEvent event = history.getEvents().get(0);
316317
if (!isWorkflowExecutionCompletedEvent(event)) {
@@ -326,7 +327,12 @@ private static CompletableFuture<HistoryEvent> getInstanceCloseEventAsync(
326327
.getWorkflowExecutionContinuedAsNewEventAttributes()
327328
.getNewExecutionRunId());
328329
return getInstanceCloseEventAsync(
329-
service, domain, nextWorkflowExecution, r.getNextPageToken(), timeout, unit);
330+
service,
331+
domain,
332+
nextWorkflowExecution,
333+
r.getNextPageToken(),
334+
timeout - elapsedTime,
335+
unit);
330336
}
331337
return CompletableFuture.completedFuture(event);
332338
});

0 commit comments

Comments
 (0)