|
22 | 22 | import io.temporal.activity.Activity; |
23 | 23 | import io.temporal.activity.ActivityInterface; |
24 | 24 | import io.temporal.activity.ActivityOptions; |
25 | | -import io.temporal.client.DuplicateWorkflowException; |
26 | 25 | import io.temporal.client.WorkflowClient; |
| 26 | +import io.temporal.client.WorkflowExecutionAlreadyStarted; |
27 | 27 | import io.temporal.client.WorkflowOptions; |
28 | | -import io.temporal.proto.common.WorkflowExecution; |
| 28 | +import io.temporal.common.v1.WorkflowExecution; |
29 | 29 | import io.temporal.serviceclient.WorkflowServiceStubs; |
30 | 30 | import io.temporal.worker.Worker; |
31 | 31 | import io.temporal.worker.WorkerFactory; |
@@ -82,7 +82,8 @@ public void greet(String name) { |
82 | 82 | static class GreetingActivitiesImpl implements GreetingActivities { |
83 | 83 | @Override |
84 | 84 | public void greet(String greeting) { |
85 | | - System.out.println("From " + Activity.getWorkflowExecution() + ": " + greeting); |
| 85 | + System.out.println( |
| 86 | + "From " + Activity.getExecutionContext().getInfo().getWorkflowId() + ": " + greeting); |
86 | 87 | } |
87 | 88 | } |
88 | 89 |
|
@@ -114,13 +115,17 @@ public static void main(String[] args) throws InterruptedException { |
114 | 115 | .setWorkflowId(CRON_WORKFLOW_ID) |
115 | 116 | .setTaskList(TASK_LIST) |
116 | 117 | .setCronSchedule("* * * * *") |
| 118 | + // Execution timeout limits total time. Cron will stop executing after this timeout. |
| 119 | + .setWorkflowExecutionTimeout(Duration.ofMinutes(10)) |
| 120 | + // Run timeout limits duration of a single workflow invocation. |
| 121 | + .setWorkflowRunTimeout(Duration.ofMinutes(1)) |
117 | 122 | .build(); |
118 | 123 | // WorkflowOptions.newBuilder().setCronSchedule("@every 2s").build(); |
119 | 124 | GreetingWorkflow workflow = client.newWorkflowStub(GreetingWorkflow.class, workflowOptions); |
120 | 125 | try { |
121 | 126 | WorkflowExecution execution = WorkflowClient.start(workflow::greet, "World"); |
122 | 127 | System.out.println("Started " + execution); |
123 | | - } catch (DuplicateWorkflowException e) { |
| 128 | + } catch (WorkflowExecutionAlreadyStarted e) { |
124 | 129 | System.out.println("Already running as " + e.getExecution()); |
125 | 130 | } catch (Throwable e) { |
126 | 131 | e.printStackTrace(); |
|
0 commit comments