Skip to content

Commit 1d3395d

Browse files
committed
address comments 2: workflow exec overloads
1 parent 49574ac commit 1d3395d

5 files changed

Lines changed: 83 additions & 14 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ jobs:
120120
--dynamic-config-value history.enableChasm=true \
121121
--dynamic-config-value history.enableCHASMSignalBacklinks=true \
122122
--dynamic-config-value history.enableTransitionHistory=true \
123+
--dynamic-config-value history.enableUpdateCallbacks=true \
124+
--dynamic-config-value history.enableCHASMCallbacks=true \
123125
--dynamic-config-value frontend.enableCancelWorkerPollsOnShutdown=true \
124126
--dynamic-config-value frontend.workerCommandsEnabled=true \
125127
--dynamic-config-value system.enableCancelActivityWorkerCommand=true &

temporal-sdk/src/main/java/io/temporal/nexus/CancelUpdateWorkflowInput.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.temporal.nexus;
22

3-
import com.google.common.base.Strings;
43
import io.temporal.common.Experimental;
54
import java.util.Objects;
65

@@ -17,7 +16,7 @@ public final class CancelUpdateWorkflowInput {
1716

1817
public CancelUpdateWorkflowInput(String workflowId, String runId, String updateId) {
1918
this.workflowId = Objects.requireNonNull(workflowId);
20-
this.runId = Strings.nullToEmpty(runId);
19+
this.runId = Objects.requireNonNull(runId);
2120
this.updateId = Objects.requireNonNull(updateId);
2221
}
2322

temporal-sdk/src/main/java/io/temporal/nexus/TemporalNexusClient.java

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.temporal.nexus;
22

33
import io.nexusrpc.OperationException;
4+
import io.temporal.api.common.v1.WorkflowExecution;
45
import io.temporal.client.UpdateOptions;
56
import io.temporal.client.WorkflowClient;
67
import io.temporal.client.WorkflowOptions;
@@ -510,7 +511,6 @@ <R> TemporalOperationResult<R> startWorkflow(
510511
WorkflowOptions options,
511512
Object... args);
512513

513-
// draft-review: all these combinations are for 1-1 compatibility - check if they can be trimmed
514514
/**
515515
* Starts a workflow update on an existing workflow as a Nexus operation. The result is delivered
516516
* asynchronously via the Nexus completion callback, unless the update RPC comes back already
@@ -746,7 +746,45 @@ <T, A1, A2, A3, A4, A5, A6, R> TemporalOperationResult<R> startWorkflowUpdate(
746746
UpdateOptions<R> options)
747747
throws OperationException;
748748

749-
// draft-review: check if all these are also necessary to preserve 1:1 compatibility
749+
/**
750+
* TBD: determine if all the other 14 func+proc+void are required and add if needed Starts a
751+
* six-argument workflow update on the provided workflow execution. See {@link
752+
* #startWorkflowUpdate(Class, String, Functions.Func1, UpdateOptions)} for the full behavior
753+
* contract.
754+
*
755+
* @param <T>
756+
* @param <A1>
757+
* @param <A2>
758+
* @param <A3>
759+
* @param <A4>
760+
* @param <A5>
761+
* @param <A6>
762+
* @param <R>
763+
* @param workflowClass
764+
* @param execution
765+
* @param updateMethod
766+
* @param arg1
767+
* @param arg2
768+
* @param arg3
769+
* @param arg4
770+
* @param arg5
771+
* @param arg6
772+
* @param options
773+
* @return
774+
* @throws OperationException
775+
*/
776+
<T, A1, A2, A3, A4, A5, A6, R> TemporalOperationResult<R> startWorkflowUpdate(
777+
Class<T> workflowClass,
778+
WorkflowExecution execution,
779+
Functions.Func7<T, A1, A2, A3, A4, A5, A6, R> updateMethod,
780+
A1 arg1,
781+
A2 arg2,
782+
A3 arg3,
783+
A4 arg4,
784+
A5 arg5,
785+
A6 arg6,
786+
UpdateOptions<R> options)
787+
throws OperationException;
750788

751789
/**
752790
* Starts a zero-argument workflow update with no return value on an existing workflow as a Nexus

temporal-sdk/src/main/java/io/temporal/nexus/TemporalNexusClientImpl.java

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44
import com.google.common.base.Strings;
55
import io.nexusrpc.OperationException;
66
import io.nexusrpc.handler.HandlerException;
7+
import io.nexusrpc.handler.HandlerException.RetryBehavior;
78
import io.nexusrpc.handler.OperationContext;
89
import io.nexusrpc.handler.OperationStartDetails;
10+
import io.temporal.api.common.v1.WorkflowExecution;
911
import io.temporal.client.UpdateOptions;
1012
import io.temporal.client.WorkflowClient;
1113
import io.temporal.client.WorkflowOptions;
1214
import io.temporal.client.WorkflowStub;
15+
import io.temporal.client.WorkflowTargetOptions;
1316
import io.temporal.client.WorkflowUpdateException;
1417
import io.temporal.client.WorkflowUpdateHandle;
1518
import io.temporal.client.WorkflowUpdateStage;
@@ -596,15 +599,21 @@ private <R> TemporalOperationResult<R> executeUpdate(
596599
private <R> void checkNexusUpdateOptionsValid(UpdateOptions<R> options)
597600
throws OperationException {
598601
if (options.getWaitForStage() != WorkflowUpdateStage.ACCEPTED) {
599-
throw OperationException.failed(
600-
"workflow update Nexus operation only support WaitForStage Accepted");
602+
throw new HandlerException(
603+
HandlerException.ErrorType.BAD_REQUEST,
604+
"invalid update request",
605+
new IllegalArgumentException(
606+
"nexus op workflow updates only support WorkflowUpdateStageAccepted for async updates"),
607+
RetryBehavior.RETRYABLE);
601608
}
602-
// draft-review: TBD, this is still under discussion as we may want to let
603-
// handlers trigger invalid updates in some cases and just retry forever
604609
try {
605610
options.validate();
606611
} catch (IllegalStateException e) {
607-
throw OperationException.failed(e);
612+
throw new HandlerException(
613+
HandlerException.ErrorType.INTERNAL,
614+
"invalid update request",
615+
e,
616+
RetryBehavior.RETRYABLE);
608617
}
609618
}
610619

@@ -617,4 +626,28 @@ private void markAsyncOperationStarted() {
617626
+ "Use getWorkflowClient() for additional workflow interactions."));
618627
}
619628
}
629+
630+
@Override
631+
public <T, A1, A2, A3, A4, A5, A6, R> TemporalOperationResult<R> startWorkflowUpdate(
632+
Class<T> workflowClass,
633+
WorkflowExecution execution,
634+
Functions.Func7<T, A1, A2, A3, A4, A5, A6, R> updateMethod,
635+
A1 arg1,
636+
A2 arg2,
637+
A3 arg3,
638+
A4 arg4,
639+
A5 arg5,
640+
A6 arg6,
641+
UpdateOptions<R> options)
642+
throws OperationException {
643+
T stub =
644+
client.newWorkflowStub(
645+
workflowClass,
646+
WorkflowTargetOptions.newBuilder().setWorkflowExecution(execution).build());
647+
return executeUpdate(
648+
options,
649+
effective ->
650+
WorkflowClient.startUpdate(
651+
() -> updateMethod.apply(stub, arg1, arg2, arg3, arg4, arg5, arg6), effective));
652+
}
620653
}

temporal-sdk/src/test/java/io/temporal/workflow/nexus/UpdateWorkflowOperationTest.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import io.temporal.client.WorkflowUpdateStage;
1515
import io.temporal.failure.ApplicationFailure;
1616
import io.temporal.failure.NexusOperationFailure;
17-
import io.temporal.internal.common.env.EnvironmentVariableUtils;
1817
import io.temporal.internal.nexus.OperationToken;
1918
import io.temporal.internal.nexus.OperationTokenType;
2019
import io.temporal.internal.nexus.OperationTokenUtil;
@@ -111,12 +110,10 @@ public void syncCompletedUpdateReturnsResult() {
111110

112111
@Test
113112
public void asyncUpdateWorkflowOperationCompletes() {
114-
// only run this test if the server supports update completion callbacks
115-
// currently only for local server manual checks until the in-memory test
116-
// server can support update completion callbacks
113+
// Requires history.enableUpdateCallbacks and history.enableCHASMCallbacks
117114
assumeTrue(
118115
"server does not support update completion callbacks",
119-
EnvironmentVariableUtils.readBooleanFlag("UPDATE_CALLBACKS_SUPPORTED"));
116+
SDKTestWorkflowRule.useExternalService);
120117

121118
TestWorkflows.TestWorkflow1 workflowStub =
122119
testWorkflowRule.newWorkflowStubTimeoutOptions(

0 commit comments

Comments
 (0)