Skip to content

Commit ec02f6e

Browse files
authored
Changes to work with v0.23.1 of service and Java SDK (temporalio#11)
* Changed version to 0.19 * Fixed unit test * Changes to work with v23.1 * Systemexit is back
1 parent 13acc84 commit ec02f6e

34 files changed

+178
-170
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ repositories {
3636
}
3737

3838
dependencies {
39-
compile group: 'io.temporal', name: 'temporal-sdk', version: '0.19.0'
39+
compile group: 'io.temporal', name: 'temporal-sdk', version: '0.23.1'
4040

4141
compile group: 'commons-configuration', name: 'commons-configuration', version: '1.9'
4242
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'

src/main/java/io/temporal/samples/bookingsaga/TripBookingSaga.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import io.temporal.client.WorkflowClient;
2323
import io.temporal.client.WorkflowException;
24+
import io.temporal.client.WorkflowOptions;
2425
import io.temporal.serviceclient.WorkflowServiceStubs;
2526
import io.temporal.worker.Worker;
2627
import io.temporal.worker.WorkerFactory;
@@ -54,15 +55,16 @@ public static void main(String[] args) {
5455
System.out.println("Worker started for task list: " + TASK_LIST);
5556

5657
// now we can start running instances of our saga - its state will be persisted
57-
TripBookingWorkflow trip1 = client.newWorkflowStub(TripBookingWorkflow.class);
58+
WorkflowOptions options = WorkflowOptions.newBuilder().setTaskList(TASK_LIST).build();
59+
TripBookingWorkflow trip1 = client.newWorkflowStub(TripBookingWorkflow.class, options);
5860
try {
5961
trip1.bookTrip("trip1");
6062
} catch (WorkflowException e) {
6163
// Expected
6264
}
6365

6466
try {
65-
TripBookingWorkflow trip2 = client.newWorkflowStub(TripBookingWorkflow.class);
67+
TripBookingWorkflow trip2 = client.newWorkflowStub(TripBookingWorkflow.class, options);
6668
trip2.bookTrip("trip2");
6769
} catch (WorkflowException e) {
6870
// Expected

src/main/java/io/temporal/samples/bookingsaga/TripBookingWorkflow.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,11 @@
1919

2020
package io.temporal.samples.bookingsaga;
2121

22-
import static io.temporal.samples.bookingsaga.TripBookingSaga.TASK_LIST;
23-
2422
import io.temporal.workflow.WorkflowInterface;
2523
import io.temporal.workflow.WorkflowMethod;
2624

2725
@WorkflowInterface
2826
public interface TripBookingWorkflow {
29-
30-
@WorkflowMethod(executionStartToCloseTimeoutSeconds = 3600, taskList = TASK_LIST)
27+
@WorkflowMethod
3128
void bookTrip(String name);
3229
}

src/main/java/io/temporal/samples/bookingsaga/TripBookingWorkflowImpl.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package io.temporal.samples.bookingsaga;
2121

2222
import io.temporal.activity.ActivityOptions;
23+
import io.temporal.common.RetryOptions;
2324
import io.temporal.workflow.ActivityException;
2425
import io.temporal.workflow.Saga;
2526
import io.temporal.workflow.Workflow;
@@ -28,7 +29,11 @@
2829
public class TripBookingWorkflowImpl implements TripBookingWorkflow {
2930

3031
private final ActivityOptions options =
31-
ActivityOptions.newBuilder().setScheduleToCloseTimeout(Duration.ofHours(1)).build();
32+
ActivityOptions.newBuilder()
33+
.setScheduleToCloseTimeout(Duration.ofHours(1))
34+
// disable retries for example to run faster
35+
.setRetryOptions(RetryOptions.newBuilder().setMaximumAttempts(1).build())
36+
.build();
3237
private final TripBookingActivities activities =
3338
Workflow.newActivityStub(TripBookingActivities.class, options);
3439

src/main/java/io/temporal/samples/common/QueryWorkflowExecution.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
import io.temporal.client.WorkflowClient;
2323
import io.temporal.client.WorkflowStub;
24-
import io.temporal.proto.execution.WorkflowExecution;
24+
import io.temporal.proto.common.WorkflowExecution;
2525
import io.temporal.serviceclient.WorkflowServiceStubs;
2626
import java.util.Optional;
2727

src/main/java/io/temporal/samples/fileprocessing/FileProcessingStarter.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919

2020
package io.temporal.samples.fileprocessing;
2121

22+
import static io.temporal.samples.fileprocessing.FileProcessingWorker.TASK_LIST;
23+
2224
import io.temporal.client.WorkflowClient;
25+
import io.temporal.client.WorkflowOptions;
2326
import io.temporal.serviceclient.WorkflowServiceStubs;
2427
import java.net.URL;
2528

@@ -31,7 +34,10 @@ public static void main(String[] args) throws Exception {
3134
WorkflowServiceStubs service = WorkflowServiceStubs.newInstance();
3235
// client that can be used to start and signal workflows
3336
WorkflowClient client = WorkflowClient.newInstance(service);
34-
FileProcessingWorkflow workflow = client.newWorkflowStub(FileProcessingWorkflow.class);
37+
FileProcessingWorkflow workflow =
38+
client.newWorkflowStub(
39+
FileProcessingWorkflow.class,
40+
WorkflowOptions.newBuilder().setTaskList(TASK_LIST).build());
3541

3642
System.out.println("Executing FileProcessingWorkflow");
3743

src/main/java/io/temporal/samples/fileprocessing/FileProcessingWorkflow.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@
2626
/** Contract for file processing workflow. */
2727
@WorkflowInterface
2828
public interface FileProcessingWorkflow {
29-
30-
@WorkflowMethod(
31-
taskList = FileProcessingWorker.TASK_LIST,
32-
executionStartToCloseTimeoutSeconds = 30
33-
)
29+
@WorkflowMethod
3430
void processFile(URL source, URL destination);
3531
}

src/main/java/io/temporal/samples/fileprocessing/FileProcessingWorkflowImpl.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import io.temporal.workflow.Workflow;
2525
import java.net.URL;
2626
import java.time.Duration;
27+
import java.util.Optional;
2728

2829
/**
2930
* This implementation of FileProcessingWorkflow downloads the file, zips it, and uploads it to a
@@ -51,12 +52,12 @@ public FileProcessingWorkflowImpl() {
5152
@Override
5253
public void processFile(URL source, URL destination) {
5354
RetryOptions retryOptions =
54-
RetryOptions.newBuilder()
55-
.setExpiration(Duration.ofSeconds(10))
56-
.setInitialInterval(Duration.ofSeconds(1))
57-
.build();
55+
RetryOptions.newBuilder().setInitialInterval(Duration.ofSeconds(1)).build();
5856
// Retries the whole sequence on any failure, potentially on a different host.
59-
Workflow.retry(retryOptions, () -> processFileImpl(source, destination));
57+
Workflow.retry(
58+
retryOptions,
59+
Optional.of(Duration.ofSeconds(10)),
60+
() -> processFileImpl(source, destination));
6061
}
6162

6263
private void processFileImpl(URL source, URL destination) {

src/main/java/io/temporal/samples/hello/HelloActivity.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import io.temporal.activity.ActivityMethod;
2424
import io.temporal.activity.ActivityOptions;
2525
import io.temporal.client.WorkflowClient;
26+
import io.temporal.client.WorkflowOptions;
2627
import io.temporal.serviceclient.WorkflowServiceStubs;
2728
import io.temporal.worker.Worker;
2829
import io.temporal.worker.WorkerFactory;
@@ -43,7 +44,7 @@ public class HelloActivity {
4344
@WorkflowInterface
4445
public interface GreetingWorkflow {
4546
/** @return greeting string */
46-
@WorkflowMethod(executionStartToCloseTimeoutSeconds = 10, taskList = TASK_LIST)
47+
@WorkflowMethod
4748
String getGreeting(String name);
4849
}
4950

@@ -100,7 +101,9 @@ public static void main(String[] args) {
100101

101102
// Start a workflow execution. Usually this is done from another program.
102103
// Uses task list from the GreetingWorkflow @WorkflowMethod annotation.
103-
GreetingWorkflow workflow = client.newWorkflowStub(GreetingWorkflow.class);
104+
GreetingWorkflow workflow =
105+
client.newWorkflowStub(
106+
GreetingWorkflow.class, WorkflowOptions.newBuilder().setTaskList(TASK_LIST).build());
104107
// Execute a workflow waiting for it to complete. See {@link
105108
// io.temporal.samples.hello.HelloSignal}
106109
// for an example of starting workflow without waiting synchronously for its result.

src/main/java/io/temporal/samples/hello/HelloActivityRetry.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ public static class GreetingWorkflowImpl implements GreetingWorkflow {
7272
.setRetryOptions(
7373
RetryOptions.newBuilder()
7474
.setInitialInterval(Duration.ofSeconds(1))
75-
.setExpiration(Duration.ofMinutes(1))
7675
.setDoNotRetry(IllegalArgumentException.class)
7776
.build())
7877
.build());
@@ -122,11 +121,7 @@ public static void main(String[] args) {
122121
factory.start();
123122

124123
// Get a workflow stub using the same task list the worker uses.
125-
WorkflowOptions workflowOptions =
126-
WorkflowOptions.newBuilder()
127-
.setTaskList(TASK_LIST)
128-
.setExecutionStartToCloseTimeout(Duration.ofSeconds(30))
129-
.build();
124+
WorkflowOptions workflowOptions = WorkflowOptions.newBuilder().setTaskList(TASK_LIST).build();
130125
GreetingWorkflow workflow = client.newWorkflowStub(GreetingWorkflow.class, workflowOptions);
131126
// Execute a workflow waiting for it to complete.
132127
String greeting = workflow.getGreeting("World");

0 commit comments

Comments
 (0)