Skip to content

Commit 8cf9ed5

Browse files
committed
set random uuid instead of fixed value
Using a fixed value for SideEffects, does not explain the usecase very well. It should be used with values which are unknown beforehand.
1 parent 6560530 commit 8cf9ed5

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

src/main/java/com/uber/cadence/samples/hello/HelloSideEffect.java

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.uber.cadence.workflow.QueryMethod;
88
import com.uber.cadence.workflow.Workflow;
99
import com.uber.cadence.workflow.WorkflowMethod;
10+
import java.util.UUID;
1011

1112
/**
1213
* Hello SideEffect Cadence workflow that sets a SideEffect. The set value can be queried Requires a
@@ -19,7 +20,7 @@ public class HelloSideEffect {
1920
/** Workflow interface has to have at least one method annotated with @WorkflowMethod. */
2021
public interface SideEffectWorkflow {
2122
@WorkflowMethod(executionStartToCloseTimeoutSeconds = 10, taskList = TASK_LIST)
22-
void set(String value);
23+
void start();
2324

2425
/** @return set value */
2526
@QueryMethod
@@ -31,18 +32,13 @@ public static class SideEffectWorkflowImpl implements SideEffectWorkflow {
3132
private String value = "";
3233

3334
@Override
34-
public void set(String value) {
35-
Workflow.sideEffect(
36-
String.class,
37-
() -> {
38-
return value;
39-
});
40-
Workflow.sideEffect(
41-
Boolean.class,
42-
() -> {
43-
return true;
44-
});
45-
this.value = value;
35+
public void start() {
36+
this.value =
37+
Workflow.sideEffect(
38+
String.class,
39+
() -> {
40+
return UUID.randomUUID().toString();
41+
});
4642
}
4743

4844
@Override
@@ -65,7 +61,7 @@ public static void main(String[] args) {
6561
// Get a workflow stub using the same task list the worker uses.
6662
SideEffectWorkflow workflow = workflowClient.newWorkflowStub(SideEffectWorkflow.class);
6763
// Execute a workflow waiting for it to complete.
68-
workflow.set("test");
64+
workflow.start();
6965
// Query and print the set value
7066
System.out.println(workflow.get());
7167
System.exit(0);

0 commit comments

Comments
 (0)