Skip to content

Commit 21b7363

Browse files
author
Maxim Fateev
committed
Added timeouts to annotations
1 parent 49e77f6 commit 21b7363

15 files changed

+74
-78
lines changed

src/main/java/com/uber/cadence/samples/fileprocessing/FileProcessingStarter.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,7 @@ public static void main(String[] args) throws Exception {
5454
workflowArgs.setTargetFilename(targetFilename);
5555

5656
WorkflowClient workflowClient = WorkflowClient.newInstance(swfService, domain);
57-
WorkflowOptions options = new WorkflowOptions.Builder()
58-
.setExecutionStartToCloseTimeoutSeconds(300)
59-
.setTaskList(WORKFLOW_TASK_LIST)
60-
.build();
61-
FileProcessingWorkflow workflow = workflowClient.newWorkflowStub(FileProcessingWorkflow.class, options);
57+
FileProcessingWorkflow workflow = workflowClient.newWorkflowStub(FileProcessingWorkflow.class);
6258

6359
// This is going to block until the workflow completion.
6460
// This is rarely used in production. Use the commented code below for async start version.

src/main/java/com/uber/cadence/samples/fileprocessing/FileProcessingWorkflow.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public void setTargetFilename(String targetFilename) {
6868
/**
6969
* Uses a structure as arguments, to make addition of new arguments a backwards compatible change.
7070
*/
71-
@WorkflowMethod
71+
@WorkflowMethod(taskList = FileProcessingStarter.WORKFLOW_TASK_LIST,
72+
executionStartToCloseTimeoutSeconds = 300)
7273
void processFile(Arguments args);
7374
}

src/main/java/com/uber/cadence/samples/fileprocessing/FileProcessingWorkflowZipImpl.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616
*/
1717
package com.uber.cadence.samples.fileprocessing;
1818

19-
import com.uber.cadence.workflow.ActivityOptions;
19+
import com.uber.cadence.activity.ActivityOptions;
2020
import com.uber.cadence.workflow.Workflow;
2121

2222
import java.io.File;
23+
import java.time.Duration;
2324
import java.util.ArrayList;
2425
import java.util.List;
2526

@@ -38,7 +39,7 @@ public class FileProcessingWorkflowZipImpl implements FileProcessingWorkflow {
3839
public FileProcessingWorkflowZipImpl() {
3940
// Create activity clients
4041
ActivityOptions ao = new ActivityOptions.Builder()
41-
.setScheduleToCloseTimeoutSeconds(60)
42+
.setScheduleToCloseTimeout(Duration.ofMinutes(1))
4243
.setTaskList(FileProcessingWorker.TASK_LIST)
4344
.build();
4445
this.defaultTaskListStore = Workflow.newActivityStub(SimpleStoreActivities.class, ao);
@@ -67,8 +68,8 @@ public void processFile(Arguments args) {
6768

6869
// Now initialize stubs that are specific to the returned task list.
6970
ActivityOptions hostAO = new ActivityOptions.Builder()
70-
.setScheduleToCloseTimeoutSeconds(60)
71-
.setScheduleToStartTimeoutSeconds(10) // short queueing timeout
71+
.setScheduleToCloseTimeout(Duration.ofMinutes(1))
72+
.setScheduleToStartTimeout(Duration.ofSeconds(10)) // short queueing timeout
7273
.setTaskList(workerTaskList)
7374
.build();
7475
workerTaskListStore = Workflow.newActivityStub(SimpleStoreActivities.class, hostAO);

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

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
*/
1717
package com.uber.cadence.samples.hello;
1818

19+
import com.uber.cadence.activity.ActivityMethod;
1920
import com.uber.cadence.client.WorkflowClient;
20-
import com.uber.cadence.client.WorkflowOptions;
2121
import com.uber.cadence.worker.Worker;
22-
import com.uber.cadence.workflow.ActivityOptions;
2322
import com.uber.cadence.workflow.Workflow;
2423
import com.uber.cadence.workflow.WorkflowMethod;
24+
import org.apache.log4j.BasicConfigurator;
2525

2626
import static com.uber.cadence.samples.common.SampleConstants.DOMAIN;
2727

@@ -40,14 +40,15 @@ public interface GreetingWorkflow {
4040
/**
4141
* @return greeting string
4242
*/
43-
@WorkflowMethod
43+
@WorkflowMethod(executionStartToCloseTimeoutSeconds = 10, taskList = TASK_LIST)
4444
String getGreeting(String name);
4545
}
4646

4747
/**
4848
* Activity interface is just a POJI
4949
*/
5050
public interface GreetingActivities {
51+
@ActivityMethod(scheduleToCloseTimeoutSeconds = 2)
5152
String composeGreeting(String greeting, String name);
5253
}
5354

@@ -60,9 +61,7 @@ public static class GreetingWorkflowImpl implements GreetingWorkflow {
6061
* Activity stub implements activity interface and proxies calls to it to Cadence activity invocations.
6162
* As activities are reentrant only a single stub can be used for multiple activity invocations.
6263
*/
63-
private final GreetingActivities activities = Workflow.newActivityStub(
64-
GreetingActivities.class,
65-
new ActivityOptions.Builder().setScheduleToCloseTimeoutSeconds(10).build());
64+
private final GreetingActivities activities = Workflow.newActivityStub(GreetingActivities.class);
6665

6766
@Override
6867
public String getGreeting(String name) {
@@ -91,12 +90,7 @@ public static void main(String[] args) {
9190
// Start a workflow execution. Usually it is done from another program.
9291
WorkflowClient workflowClient = WorkflowClient.newInstance(DOMAIN);
9392
// Get a workflow stub using the same task list the worker uses.
94-
WorkflowOptions workflowOptions = new WorkflowOptions.Builder()
95-
.setTaskList(TASK_LIST)
96-
.setExecutionStartToCloseTimeoutSeconds(30)
97-
.build();
98-
GreetingWorkflow workflow = workflowClient.newWorkflowStub(GreetingWorkflow.class,
99-
workflowOptions);
93+
GreetingWorkflow workflow = workflowClient.newWorkflowStub(GreetingWorkflow.class);
10094
// Execute a workflow waiting for it complete.
10195
String greeting = workflow.getGreeting("World");
10296
System.out.println(greeting);

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@
1616
*/
1717
package com.uber.cadence.samples.hello;
1818

19+
import com.uber.cadence.activity.ActivityOptions;
1920
import com.uber.cadence.client.WorkflowClient;
2021
import com.uber.cadence.client.WorkflowOptions;
22+
import com.uber.cadence.common.RetryOptions;
2123
import com.uber.cadence.worker.Worker;
22-
import com.uber.cadence.workflow.ActivityOptions;
2324
import com.uber.cadence.workflow.Functions;
24-
import com.uber.cadence.workflow.RetryOptions;
2525
import com.uber.cadence.workflow.Workflow;
2626
import com.uber.cadence.workflow.WorkflowMethod;
27+
import org.apache.log4j.BasicConfigurator;
2728

2829
import java.time.Duration;
2930

@@ -63,10 +64,11 @@ public static class GreetingWorkflowImpl implements GreetingWorkflow {
6364
private final GreetingActivities activities = Workflow.newActivityStub(
6465
GreetingActivities.class,
6566
new ActivityOptions.Builder()
66-
.setScheduleToCloseTimeoutSeconds(10)
67+
.setScheduleToCloseTimeout(Duration.ofSeconds(10))
6768
.setRetryOptions(new RetryOptions.Builder()
6869
.setInitialInterval(Duration.ofSeconds(1))
6970
.setExpiration(Duration.ofMinutes(1))
71+
.setDoNotRetry(IllegalArgumentException.class)
7072
.build())
7173
.build());
7274

@@ -112,7 +114,7 @@ public static void main(String[] args) {
112114
// Get a workflow stub using the same task list the worker uses.
113115
WorkflowOptions workflowOptions = new WorkflowOptions.Builder()
114116
.setTaskList(TASK_LIST)
115-
.setExecutionStartToCloseTimeoutSeconds(30)
117+
.setExecutionStartToCloseTimeout(Duration.ofSeconds(30))
116118
.build();
117119
GreetingWorkflow workflow = workflowClient.newWorkflowStub(GreetingWorkflow.class,
118120
workflowOptions);

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

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
*/
1717
package com.uber.cadence.samples.hello;
1818

19+
import com.uber.cadence.activity.ActivityMethod;
1920
import com.uber.cadence.client.WorkflowClient;
2021
import com.uber.cadence.client.WorkflowOptions;
2122
import com.uber.cadence.worker.Worker;
22-
import com.uber.cadence.workflow.ActivityOptions;
2323
import com.uber.cadence.workflow.Async;
2424
import com.uber.cadence.workflow.Functions;
2525
import com.uber.cadence.workflow.Promise;
@@ -37,11 +37,12 @@ public class HelloAsync {
3737
private static final String TASK_LIST = "HelloActivity";
3838

3939
public interface GreetingWorkflow {
40-
@WorkflowMethod
40+
@WorkflowMethod(executionStartToCloseTimeoutSeconds = 15, taskList = TASK_LIST)
4141
String getGreeting(String name);
4242
}
4343

4444
public interface GreetingActivities {
45+
@ActivityMethod(scheduleToCloseTimeoutSeconds = 10)
4546
String composeGreeting(String greeting, String name);
4647
}
4748

@@ -55,9 +56,7 @@ public static class GreetingWorkflowImpl implements GreetingWorkflow {
5556
* Activity stub implements activity interface and proxies calls to it to Cadence activity invocations.
5657
* As activities are reentrant only a single stub can be used for multiple activity invocations.
5758
*/
58-
private final GreetingActivities activities = Workflow.newActivityStub(
59-
GreetingActivities.class,
60-
new ActivityOptions.Builder().setScheduleToCloseTimeoutSeconds(10).build());
59+
private final GreetingActivities activities = Workflow.newActivityStub(GreetingActivities.class);
6160

6261
@Override
6362
public String getGreeting(String name) {
@@ -90,12 +89,7 @@ public static void main(String[] args) {
9089
// Start a workflow execution. Usually it is done from another program.
9190
WorkflowClient workflowClient = WorkflowClient.newInstance(DOMAIN);
9291
// Get a workflow stub using the same task list the worker uses.
93-
WorkflowOptions workflowOptions = new WorkflowOptions.Builder()
94-
.setTaskList(TASK_LIST)
95-
.setExecutionStartToCloseTimeoutSeconds(30)
96-
.build();
97-
GreetingWorkflow workflow = workflowClient.newWorkflowStub(GreetingWorkflow.class,
98-
workflowOptions);
92+
GreetingWorkflow workflow = workflowClient.newWorkflowStub(GreetingWorkflow.class);
9993
// Execute a workflow waiting for it complete.
10094
String greeting = workflow.getGreeting("World");
10195
System.out.println(greeting);

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

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@
1717
package com.uber.cadence.samples.hello;
1818

1919
import com.uber.cadence.activity.Activity;
20+
import com.uber.cadence.activity.ActivityMethod;
2021
import com.uber.cadence.activity.DoNotCompleteOnReturn;
2122
import com.uber.cadence.client.ActivityCompletionClient;
2223
import com.uber.cadence.client.WorkflowClient;
23-
import com.uber.cadence.client.WorkflowOptions;
2424
import com.uber.cadence.worker.Worker;
25-
import com.uber.cadence.workflow.ActivityOptions;
2625
import com.uber.cadence.workflow.Workflow;
2726
import com.uber.cadence.workflow.WorkflowMethod;
2827

@@ -42,14 +41,15 @@ public interface GreetingWorkflow {
4241
/**
4342
* @return greeting string
4443
*/
45-
@WorkflowMethod
44+
@WorkflowMethod(executionStartToCloseTimeoutSeconds = 15, taskList = TASK_LIST)
4645
String getGreeting(String name);
4746
}
4847

4948
/**
5049
* Activity interface is just a POJI
5150
*/
5251
public interface GreetingActivities {
52+
@ActivityMethod(scheduleToCloseTimeoutSeconds = 10)
5353
String composeGreeting(String greeting, String name);
5454
}
5555

@@ -62,9 +62,7 @@ public static class GreetingWorkflowImpl implements GreetingWorkflow {
6262
* Activity stub implements activity interface and proxies calls to it to Cadence activity invocations.
6363
* As activities are reentrant only a single stub can be used for multiple activity invocations.
6464
*/
65-
private final GreetingActivities activities = Workflow.newActivityStub(
66-
GreetingActivities.class,
67-
new ActivityOptions.Builder().setScheduleToCloseTimeoutSeconds(10).build());
65+
private final GreetingActivities activities = Workflow.newActivityStub(GreetingActivities.class);
6866

6967
@Override
7068
public String getGreeting(String name) {
@@ -113,12 +111,7 @@ public static void main(String[] args) {
113111
// Start a workflow execution. Usually it is done from another program.
114112
WorkflowClient workflowClient = WorkflowClient.newInstance(DOMAIN);
115113
// Get a workflow stub using the same task list the worker uses.
116-
WorkflowOptions workflowOptions = new WorkflowOptions.Builder()
117-
.setTaskList(TASK_LIST)
118-
.setExecutionStartToCloseTimeoutSeconds(30)
119-
.build();
120-
GreetingWorkflow workflow = workflowClient.newWorkflowStub(GreetingWorkflow.class,
121-
workflowOptions);
114+
GreetingWorkflow workflow = workflowClient.newWorkflowStub(GreetingWorkflow.class);
122115
// Execute a workflow waiting for it complete.
123116
String greeting = workflow.getGreeting("World");
124117
System.out.println(greeting);

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,17 @@
1616
*/
1717
package com.uber.cadence.samples.hello;
1818

19+
import com.uber.cadence.activity.ActivityOptions;
1920
import com.uber.cadence.client.WorkflowClient;
2021
import com.uber.cadence.client.WorkflowOptions;
2122
import com.uber.cadence.worker.Worker;
22-
import com.uber.cadence.workflow.ActivityOptions;
2323
import com.uber.cadence.workflow.Async;
24-
import com.uber.cadence.workflow.CompletablePromise;
2524
import com.uber.cadence.workflow.Promise;
2625
import com.uber.cadence.workflow.Workflow;
2726
import com.uber.cadence.workflow.WorkflowMethod;
2827

28+
import java.time.Duration;
29+
2930
import static com.uber.cadence.samples.common.SampleConstants.DOMAIN;
3031

3132
/**
@@ -64,7 +65,7 @@ public static class GreetingWorkflowImpl implements GreetingWorkflow {
6465
*/
6566
private final GreetingActivities activities = Workflow.newActivityStub(
6667
GreetingActivities.class,
67-
new ActivityOptions.Builder().setScheduleToCloseTimeoutSeconds(10).build());
68+
new ActivityOptions.Builder().setScheduleToCloseTimeout(Duration.ofSeconds(10)).build());
6869

6970
@Override
7071
public String getGreeting(String name) {
@@ -111,7 +112,7 @@ public static void main(String[] args) {
111112
// Get a workflow stub using the same task list the worker uses.
112113
WorkflowOptions workflowOptions = new WorkflowOptions.Builder()
113114
.setTaskList(TASK_LIST)
114-
.setExecutionStartToCloseTimeoutSeconds(30)
115+
.setExecutionStartToCloseTimeout(Duration.ofSeconds(30))
115116
.build();
116117
GreetingWorkflow workflow = workflowClient.newWorkflowStub(GreetingWorkflow.class,
117118
workflowOptions);

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package com.uber.cadence.samples.hello;
1818

1919
import com.uber.cadence.client.WorkflowClient;
20-
import com.uber.cadence.client.WorkflowOptions;
2120
import com.uber.cadence.worker.Worker;
2221
import com.uber.cadence.workflow.Async;
2322
import com.uber.cadence.workflow.Promise;
@@ -44,7 +43,7 @@ public interface GreetingWorkflow {
4443
/**
4544
* @return greeting string
4645
*/
47-
@WorkflowMethod
46+
@WorkflowMethod(executionStartToCloseTimeoutSeconds = 10, taskList = TASK_LIST)
4847
String getGreeting(String name);
4948
}
5049

@@ -97,12 +96,7 @@ public static void main(String[] args) {
9796
// Start a workflow execution. Usually it is done from another program.
9897
WorkflowClient workflowClient = WorkflowClient.newInstance(DOMAIN);
9998
// Get a workflow stub using the same task list the worker uses.
100-
WorkflowOptions workflowOptions = new WorkflowOptions.Builder()
101-
.setTaskList(TASK_LIST)
102-
.setExecutionStartToCloseTimeoutSeconds(30)
103-
.build();
104-
GreetingWorkflow workflow = workflowClient.newWorkflowStub(GreetingWorkflow.class,
105-
workflowOptions);
99+
GreetingWorkflow workflow = workflowClient.newWorkflowStub(GreetingWorkflow.class);
106100
// Execute a workflow waiting for it complete.
107101
String greeting = workflow.getGreeting("World");
108102
System.out.println(greeting);

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,19 @@
1717
package com.uber.cadence.samples.hello;
1818

1919
import com.google.common.base.Throwables;
20+
import com.uber.cadence.activity.ActivityOptions;
2021
import com.uber.cadence.client.WorkflowClient;
2122
import com.uber.cadence.client.WorkflowException;
2223
import com.uber.cadence.client.WorkflowOptions;
2324
import com.uber.cadence.worker.Worker;
24-
import com.uber.cadence.workflow.ActivityOptions;
2525
import com.uber.cadence.workflow.Workflow;
2626
import com.uber.cadence.workflow.WorkflowMethod;
2727
import org.apache.log4j.BasicConfigurator;
2828
import org.apache.log4j.Level;
2929
import org.apache.log4j.Logger;
3030

3131
import java.io.IOException;
32+
import java.time.Duration;
3233

3334
import static com.uber.cadence.samples.common.SampleConstants.DOMAIN;
3435

@@ -135,7 +136,7 @@ public String getGreeting(String name) {
135136
public static class GreetingChildImpl implements GreetingChild {
136137
private final GreetingActivities activities = Workflow.newActivityStub(
137138
GreetingActivities.class,
138-
new ActivityOptions.Builder().setScheduleToCloseTimeoutSeconds(10).build());
139+
new ActivityOptions.Builder().setScheduleToCloseTimeout(Duration.ofSeconds(10)).build());
139140

140141
@Override
141142
public String composeGreeting(String greeting, String name) {
@@ -166,7 +167,7 @@ public static void main(String[] args) {
166167
WorkflowClient workflowClient = WorkflowClient.newInstance(DOMAIN);
167168
WorkflowOptions workflowOptions = new WorkflowOptions.Builder()
168169
.setTaskList(TASK_LIST)
169-
.setExecutionStartToCloseTimeoutSeconds(30)
170+
.setExecutionStartToCloseTimeout(Duration.ofSeconds(30))
170171
.build();
171172
GreetingWorkflow workflow = workflowClient.newWorkflowStub(GreetingWorkflow.class,
172173
workflowOptions);

0 commit comments

Comments
 (0)