Skip to content

Commit 94424c8

Browse files
Treat UpdateWorkflowExecution as a long poll (#1784)
1 parent bff4b6f commit 94424c8

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

temporal-sdk/src/main/java/io/temporal/internal/client/RootWorkflowClientInvoker.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949

5050
public class RootWorkflowClientInvoker implements WorkflowClientCallsInterceptor {
5151
private static final Logger log = LoggerFactory.getLogger(RootWorkflowClientInvoker.class);
52+
private static final long POLL_UPDATE_TIMEOUT_S = 60L;
5253

5354
private final GenericWorkflowClient genericClient;
5455
private final WorkflowClientOptions clientOptions;
@@ -324,7 +325,9 @@ public <R> StartUpdateOutput<R> startUpdate(StartUpdateInput<R> input) {
324325
.setFirstExecutionRunId(input.getFirstExecutionRunId())
325326
.setRequest(request)
326327
.build();
327-
UpdateWorkflowExecutionResponse result = genericClient.update(updateRequest);
328+
Deadline pollTimeoutDeadline = Deadline.after(POLL_UPDATE_TIMEOUT_S, TimeUnit.SECONDS);
329+
UpdateWorkflowExecutionResponse result =
330+
genericClient.update(updateRequest, pollTimeoutDeadline);
328331

329332
if (result.hasOutcome()) {
330333
switch (result.getOutcome().getValueCase()) {
@@ -424,7 +427,8 @@ private void pollWorkflowUpdateHelper(
424427
PollWorkflowExecutionUpdateRequest request,
425428
Deadline deadline) {
426429

427-
Deadline pollTimeoutDeadline = Deadline.after(60L, TimeUnit.SECONDS).minimum(deadline);
430+
Deadline pollTimeoutDeadline =
431+
Deadline.after(POLL_UPDATE_TIMEOUT_S, TimeUnit.SECONDS).minimum(deadline);
428432
genericClient
429433
.pollUpdateAsync(request, pollTimeoutDeadline)
430434
.whenComplete(

temporal-sdk/src/main/java/io/temporal/internal/client/external/GenericWorkflowClient.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ SignalWithStartWorkflowExecutionResponse signalWithStart(
4040
QueryWorkflowResponse query(QueryWorkflowRequest queryParameters);
4141

4242
@Experimental
43-
UpdateWorkflowExecutionResponse update(UpdateWorkflowExecutionRequest updateParameters);
43+
UpdateWorkflowExecutionResponse update(
44+
@Nonnull UpdateWorkflowExecutionRequest updateParameters, @Nonnull Deadline deadline);
4445

4546
@Experimental
4647
CompletableFuture<PollWorkflowExecutionUpdateResponse> pollUpdateAsync(

temporal-sdk/src/main/java/io/temporal/internal/client/external/GenericWorkflowClientImpl.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,8 @@ private static <T> CompletableFuture<T> toCompletableFuture(
318318
}
319319

320320
@Override
321-
public UpdateWorkflowExecutionResponse update(UpdateWorkflowExecutionRequest updateParameters) {
321+
public UpdateWorkflowExecutionResponse update(
322+
@Nonnull UpdateWorkflowExecutionRequest updateParameters, @Nonnull Deadline deadline) {
322323
Map<String, String> tags =
323324
new ImmutableMap.Builder<String, String>(1)
324325
.put(MetricsTag.UPDATE_NAME, updateParameters.getRequest().getInput().getName())
@@ -329,9 +330,10 @@ public UpdateWorkflowExecutionResponse update(UpdateWorkflowExecutionRequest upd
329330
() ->
330331
service
331332
.blockingStub()
333+
.withDeadline(deadline)
332334
.withOption(METRICS_TAGS_CALL_OPTIONS_KEY, scope)
333335
.updateWorkflowExecution(updateParameters),
334-
grpcRetryerOptions);
336+
new GrpcRetryer.GrpcRetryerOptions(DefaultStubLongPollRpcRetryOptions.INSTANCE, deadline));
335337
}
336338

337339
@Override

temporal-serviceclient/src/main/java/io/temporal/serviceclient/LongPollUtil.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ static <ReqT, RespT> boolean isLongPoll(
3030
MethodDescriptor<ReqT, RespT> method, CallOptions callOptions) {
3131
if (method == WorkflowServiceGrpc.getPollWorkflowTaskQueueMethod()
3232
|| method == WorkflowServiceGrpc.getPollActivityTaskQueueMethod()
33+
|| method == WorkflowServiceGrpc.getUpdateWorkflowExecutionMethod()
3334
|| method == WorkflowServiceGrpc.getPollWorkflowExecutionUpdateMethod()) {
3435
return true;
3536
}

0 commit comments

Comments
 (0)