Skip to content

Commit b9f5b6c

Browse files
authored
Updated peridoic hello world to use annotation for all options (#10)
1 parent 86a6edc commit b9f5b6c

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

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

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,20 @@ public class HelloPeriodic {
4343
private static final String TASK_LIST = "HelloPeriodic";
4444

4545
public interface GreetingWorkflow {
46-
@WorkflowMethod
46+
/**
47+
* Use single fixed ID to ensure that there is at most one instance running.
48+
* To run multiple instances set different ids through
49+
* WorkflowOptions passed to WorkflowClient.newWorkflowStub call.
50+
*/
51+
@WorkflowMethod(
52+
// At most one instance
53+
workflowId = "HelloPeriodic",
54+
// To allow starting workflow with the same ID after the previous one has terminated.
55+
workflowIdReusePolicy = WorkflowIdReusePolicy.AllowDuplicate,
56+
// Adjust this value to the maximum time workflow is expected to run
57+
// It usually depends on number of repetitions and interval between them.
58+
executionStartToCloseTimeoutSeconds = 300,
59+
taskList = TASK_LIST)
4760
void greetPeriodically(String name, Duration delay);
4861
}
4962

@@ -123,22 +136,8 @@ public static void main(String[] args) throws InterruptedException {
123136
System.out.println("Previous instance failed:\n" + Throwables.getStackTraceAsString(e));
124137
}
125138
}
126-
// Get a workflow stub using the same task list the worker uses.
127-
WorkflowOptions workflowOptions = new WorkflowOptions.Builder()
128-
.setTaskList(TASK_LIST)
129-
// Adjust this value to the maximum time workflow is expected to run
130-
// It usually depends on number of repetitions and interval between them.
131-
.setExecutionStartToCloseTimeout(Duration.ofMinutes(10))
132-
// Use single fixed ID to ensure that there is at most one instance running.
133-
// Obviously if there is need to run multiple instances adjust the ID appropriately to have one
134-
// per periodic business process.
135-
.setWorkflowId("HelloPeriodic")
136-
// To allow starting workflow with the same ID after the previous one has terminated.
137-
.setWorkflowIdReusePolicy(WorkflowIdReusePolicy.AllowDuplicate)
138-
.build();
139139
// New stub instance should be created for each new workflow start.
140-
GreetingWorkflow workflow = workflowClient.newWorkflowStub(GreetingWorkflow.class,
141-
workflowOptions);
140+
GreetingWorkflow workflow = workflowClient.newWorkflowStub(GreetingWorkflow.class);
142141
try {
143142
execution = WorkflowClient.asyncStart(workflow::greetPeriodically,
144143
"World", Duration.ofSeconds(1));

0 commit comments

Comments
 (0)