Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ repositories {
}

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

compile group: 'commons-configuration', name: 'commons-configuration', version: '1.9'
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import io.temporal.client.WorkflowClient;
import io.temporal.client.WorkflowException;
import io.temporal.client.WorkflowOptions;
import io.temporal.serviceclient.WorkflowServiceStubs;
import io.temporal.worker.Worker;
import io.temporal.worker.WorkerFactory;
Expand Down Expand Up @@ -54,15 +55,16 @@ public static void main(String[] args) {
System.out.println("Worker started for task list: " + TASK_LIST);

// now we can start running instances of our saga - its state will be persisted
TripBookingWorkflow trip1 = client.newWorkflowStub(TripBookingWorkflow.class);
WorkflowOptions options = WorkflowOptions.newBuilder().setTaskList(TASK_LIST).build();
TripBookingWorkflow trip1 = client.newWorkflowStub(TripBookingWorkflow.class, options);
try {
trip1.bookTrip("trip1");
} catch (WorkflowException e) {
// Expected
}

try {
TripBookingWorkflow trip2 = client.newWorkflowStub(TripBookingWorkflow.class);
TripBookingWorkflow trip2 = client.newWorkflowStub(TripBookingWorkflow.class, options);
trip2.bookTrip("trip2");
} catch (WorkflowException e) {
// Expected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,11 @@

package io.temporal.samples.bookingsaga;

import static io.temporal.samples.bookingsaga.TripBookingSaga.TASK_LIST;

import io.temporal.workflow.WorkflowInterface;
import io.temporal.workflow.WorkflowMethod;

@WorkflowInterface
public interface TripBookingWorkflow {

@WorkflowMethod(executionStartToCloseTimeoutSeconds = 3600, taskList = TASK_LIST)
@WorkflowMethod
void bookTrip(String name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package io.temporal.samples.bookingsaga;

import io.temporal.activity.ActivityOptions;
import io.temporal.common.RetryOptions;
import io.temporal.workflow.ActivityException;
import io.temporal.workflow.Saga;
import io.temporal.workflow.Workflow;
Expand All @@ -28,7 +29,11 @@
public class TripBookingWorkflowImpl implements TripBookingWorkflow {

private final ActivityOptions options =
ActivityOptions.newBuilder().setScheduleToCloseTimeout(Duration.ofHours(1)).build();
ActivityOptions.newBuilder()
.setScheduleToCloseTimeout(Duration.ofHours(1))
// disable retries for example to run faster
.setRetryOptions(RetryOptions.newBuilder().setMaximumAttempts(1).build())
.build();
private final TripBookingActivities activities =
Workflow.newActivityStub(TripBookingActivities.class, options);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import io.temporal.client.WorkflowClient;
import io.temporal.client.WorkflowStub;
import io.temporal.proto.execution.WorkflowExecution;
import io.temporal.proto.common.WorkflowExecution;
import io.temporal.serviceclient.WorkflowServiceStubs;
import java.util.Optional;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@

package io.temporal.samples.fileprocessing;

import static io.temporal.samples.fileprocessing.FileProcessingWorker.TASK_LIST;

import io.temporal.client.WorkflowClient;
import io.temporal.client.WorkflowOptions;
import io.temporal.serviceclient.WorkflowServiceStubs;
import java.net.URL;

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@
/** Contract for file processing workflow. */
@WorkflowInterface
public interface FileProcessingWorkflow {

@WorkflowMethod(
taskList = FileProcessingWorker.TASK_LIST,
executionStartToCloseTimeoutSeconds = 30
)
@WorkflowMethod
void processFile(URL source, URL destination);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import io.temporal.workflow.Workflow;
import java.net.URL;
import java.time.Duration;
import java.util.Optional;

/**
* This implementation of FileProcessingWorkflow downloads the file, zips it, and uploads it to a
Expand Down Expand Up @@ -51,12 +52,12 @@ public FileProcessingWorkflowImpl() {
@Override
public void processFile(URL source, URL destination) {
RetryOptions retryOptions =
RetryOptions.newBuilder()
.setExpiration(Duration.ofSeconds(10))
.setInitialInterval(Duration.ofSeconds(1))
.build();
RetryOptions.newBuilder().setInitialInterval(Duration.ofSeconds(1)).build();
// Retries the whole sequence on any failure, potentially on a different host.
Workflow.retry(retryOptions, () -> processFileImpl(source, destination));
Workflow.retry(
retryOptions,
Optional.of(Duration.ofSeconds(10)),
() -> processFileImpl(source, destination));
}

private void processFileImpl(URL source, URL destination) {
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/io/temporal/samples/hello/HelloActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.temporal.activity.ActivityMethod;
import io.temporal.activity.ActivityOptions;
import io.temporal.client.WorkflowClient;
import io.temporal.client.WorkflowOptions;
import io.temporal.serviceclient.WorkflowServiceStubs;
import io.temporal.worker.Worker;
import io.temporal.worker.WorkerFactory;
Expand All @@ -43,7 +44,7 @@ public class HelloActivity {
@WorkflowInterface
public interface GreetingWorkflow {
/** @return greeting string */
@WorkflowMethod(executionStartToCloseTimeoutSeconds = 10, taskList = TASK_LIST)
@WorkflowMethod
String getGreeting(String name);
}

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

// Start a workflow execution. Usually this is done from another program.
// Uses task list from the GreetingWorkflow @WorkflowMethod annotation.
GreetingWorkflow workflow = client.newWorkflowStub(GreetingWorkflow.class);
GreetingWorkflow workflow =
client.newWorkflowStub(
GreetingWorkflow.class, WorkflowOptions.newBuilder().setTaskList(TASK_LIST).build());
// Execute a workflow waiting for it to complete. See {@link
// io.temporal.samples.hello.HelloSignal}
// for an example of starting workflow without waiting synchronously for its result.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ public static class GreetingWorkflowImpl implements GreetingWorkflow {
.setRetryOptions(
RetryOptions.newBuilder()
.setInitialInterval(Duration.ofSeconds(1))
.setExpiration(Duration.ofMinutes(1))
.setDoNotRetry(IllegalArgumentException.class)
.build())
.build());
Expand Down Expand Up @@ -122,11 +121,7 @@ public static void main(String[] args) {
factory.start();

// Get a workflow stub using the same task list the worker uses.
WorkflowOptions workflowOptions =
WorkflowOptions.newBuilder()
.setTaskList(TASK_LIST)
.setExecutionStartToCloseTimeout(Duration.ofSeconds(30))
.build();
WorkflowOptions workflowOptions = WorkflowOptions.newBuilder().setTaskList(TASK_LIST).build();
GreetingWorkflow workflow = client.newWorkflowStub(GreetingWorkflow.class, workflowOptions);
// Execute a workflow waiting for it to complete.
String greeting = workflow.getGreeting("World");
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/io/temporal/samples/hello/HelloAsync.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.temporal.activity.ActivityInterface;
import io.temporal.activity.ActivityOptions;
import io.temporal.client.WorkflowClient;
import io.temporal.client.WorkflowOptions;
import io.temporal.serviceclient.WorkflowServiceStubs;
import io.temporal.worker.Worker;
import io.temporal.worker.WorkerFactory;
Expand All @@ -43,7 +44,7 @@ public class HelloAsync {

@WorkflowInterface
public interface GreetingWorkflow {
@WorkflowMethod(executionStartToCloseTimeoutSeconds = 15, taskList = TASK_LIST)
@WorkflowMethod
String getGreeting(String name);
}

Expand Down Expand Up @@ -105,7 +106,9 @@ public static void main(String[] args) {

// Start a workflow execution. Usually this is done from another program.\n'
// Uses task list from the GreetingWorkflow @WorkflowMethod annotation.
GreetingWorkflow workflow = client.newWorkflowStub(GreetingWorkflow.class);
GreetingWorkflow workflow =
client.newWorkflowStub(
GreetingWorkflow.class, WorkflowOptions.newBuilder().setTaskList(TASK_LIST).build());
// Execute a workflow waiting for it to complete.
String greeting = workflow.getGreeting("World");
System.out.println(greeting);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import io.temporal.activity.ActivityOptions;
import io.temporal.client.ActivityCompletionClient;
import io.temporal.client.WorkflowClient;
import io.temporal.client.WorkflowOptions;
import io.temporal.serviceclient.WorkflowServiceStubs;
import io.temporal.worker.Worker;
import io.temporal.worker.WorkerFactory;
Expand All @@ -46,7 +47,7 @@ public class HelloAsyncActivityCompletion {
@WorkflowInterface
public interface GreetingWorkflow {
/** @return greeting string */
@WorkflowMethod(executionStartToCloseTimeoutSeconds = 15, taskList = TASK_LIST)
@WorkflowMethod
String getGreeting(String name);
}

Expand Down Expand Up @@ -129,7 +130,9 @@ public static void main(String[] args) throws ExecutionException, InterruptedExc

// Start a workflow execution. Usually this is done from another program.
// Uses task list from the GreetingWorkflow @WorkflowMethod annotation.
GreetingWorkflow workflow = client.newWorkflowStub(GreetingWorkflow.class);
GreetingWorkflow workflow =
client.newWorkflowStub(
GreetingWorkflow.class, WorkflowOptions.newBuilder().setTaskList(TASK_LIST).build());
// Execute a workflow asynchronously returning a future that can be used to wait for the
// workflow
// completion.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,7 @@ public static void main(String[] args) {
// Get a workflow stub using the same task list the worker uses.
// As the required ExecutionStartToCloseTimeout is not specified through the @WorkflowMethod
// annotation it has to be specified through the options.
WorkflowOptions workflowOptions =
WorkflowOptions.newBuilder()
.setTaskList(TASK_LIST)
.setExecutionStartToCloseTimeout(Duration.ofSeconds(30))
.build();
WorkflowOptions workflowOptions = WorkflowOptions.newBuilder().setTaskList(TASK_LIST).build();
GreetingWorkflow workflow = client.newWorkflowStub(GreetingWorkflow.class, workflowOptions);
// Execute a workflow waiting for it to complete.
String greeting = workflow.getGreeting("World");
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/io/temporal/samples/hello/HelloChild.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package io.temporal.samples.hello;

import io.temporal.client.WorkflowClient;
import io.temporal.client.WorkflowOptions;
import io.temporal.serviceclient.WorkflowServiceStubs;
import io.temporal.worker.Worker;
import io.temporal.worker.WorkerFactory;
Expand All @@ -40,7 +41,7 @@ public class HelloChild {
@WorkflowInterface
public interface GreetingWorkflow {
/** @return greeting string */
@WorkflowMethod(executionStartToCloseTimeoutSeconds = 10, taskList = TASK_LIST)
@WorkflowMethod
String getGreeting(String name);
}

Expand Down Expand Up @@ -94,7 +95,9 @@ public static void main(String[] args) {

// Start a workflow execution. Usually this is done from another program.
// Uses task list from the GreetingWorkflow @WorkflowMethod annotation.
GreetingWorkflow workflow = client.newWorkflowStub(GreetingWorkflow.class);
GreetingWorkflow workflow =
client.newWorkflowStub(
GreetingWorkflow.class, WorkflowOptions.newBuilder().setTaskList(TASK_LIST).build());
// Execute a workflow waiting for it to complete.
String greeting = workflow.getGreeting("World");
System.out.println(greeting);
Expand Down
23 changes: 9 additions & 14 deletions src/main/java/io/temporal/samples/hello/HelloCron.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import io.temporal.client.DuplicateWorkflowException;
import io.temporal.client.WorkflowClient;
import io.temporal.client.WorkflowOptions;
import io.temporal.proto.execution.WorkflowExecution;
import io.temporal.proto.common.WorkflowExecution;
import io.temporal.serviceclient.WorkflowServiceStubs;
import io.temporal.worker.Worker;
import io.temporal.worker.WorkerFactory;
Expand All @@ -47,18 +47,7 @@ public class HelloCron {

@WorkflowInterface
public interface GreetingWorkflow {
/**
* Use single fixed ID to ensure that there is at most one instance running. To run multiple
* instances set different IDs through WorkflowOptions passed to the
* WorkflowClient.newWorkflowStub call.
*/
@WorkflowMethod(
// At most one instance.
workflowId = CRON_WORKFLOW_ID,
// Adjust this value to the maximum time workflow is expected to run.
executionStartToCloseTimeoutSeconds = 300,
taskList = TASK_LIST
)
@WorkflowMethod
void greet(String name);
}

Expand Down Expand Up @@ -118,8 +107,14 @@ public static void main(String[] args) throws InterruptedException {
// The cron format is parsed by "https://github.com/robfig/cron" library.
// Besides the standard "* * * * *" format it supports @every and other extensions.
// Note that unit testing framework doesn't support the extensions.
// Use single fixed ID to ensure that there is at most one instance running. To run multiple
// instances set different IDs.
WorkflowOptions workflowOptions =
WorkflowOptions.newBuilder().setCronSchedule("* * * * *").build();
WorkflowOptions.newBuilder()
.setWorkflowId(CRON_WORKFLOW_ID)
.setTaskList(TASK_LIST)
.setCronSchedule("* * * * *")
.build();
// WorkflowOptions.newBuilder().setCronSchedule("@every 2s").build();
GreetingWorkflow workflow = client.newWorkflowStub(GreetingWorkflow.class, workflowOptions);
try {
Expand Down
6 changes: 1 addition & 5 deletions src/main/java/io/temporal/samples/hello/HelloException.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,7 @@ public static void main(String[] args) {
worker.registerActivitiesImplementations(new GreetingActivitiesImpl());
factory.start();

WorkflowOptions workflowOptions =
WorkflowOptions.newBuilder()
.setTaskList(TASK_LIST)
.setExecutionStartToCloseTimeout(Duration.ofSeconds(30))
.build();
WorkflowOptions workflowOptions = WorkflowOptions.newBuilder().setTaskList(TASK_LIST).build();
GreetingWorkflow workflow = client.newWorkflowStub(GreetingWorkflow.class, workflowOptions);
try {
workflow.getGreeting("World");
Expand Down
23 changes: 12 additions & 11 deletions src/main/java/io/temporal/samples/hello/HelloPeriodic.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@
import io.temporal.client.DuplicateWorkflowException;
import io.temporal.client.WorkflowClient;
import io.temporal.client.WorkflowException;
import io.temporal.client.WorkflowOptions;
import io.temporal.client.WorkflowStub;
import io.temporal.proto.execution.WorkflowExecution;
import io.temporal.proto.common.WorkflowExecution;
import io.temporal.serviceclient.WorkflowServiceStubs;
import io.temporal.worker.Worker;
import io.temporal.worker.WorkerFactory;
Expand Down Expand Up @@ -57,14 +58,7 @@ public interface GreetingWorkflow {
* instances set different IDs through WorkflowOptions passed to the
* WorkflowClient.newWorkflowStub call.
*/
@WorkflowMethod(
// At most one instance.
workflowId = PERIODIC_WORKFLOW_ID,
// Adjust this value to the maximum time workflow is expected to run.
// It usually depends on the number of repetitions and interval between them.
executionStartToCloseTimeoutSeconds = 300,
taskList = TASK_LIST
)
@WorkflowMethod
void greetPeriodically(String name);
}

Expand Down Expand Up @@ -149,13 +143,20 @@ public static void main(String[] args) throws InterruptedException {
if (execution != null) {
WorkflowStub workflow = client.newUntypedWorkflowStub(execution, Optional.empty());
try {
workflow.getResult(Void.class); //
workflow.getResult(Void.class);
} catch (WorkflowException e) {
System.out.println("Previous instance failed:\n" + Throwables.getStackTraceAsString(e));
}
}
// New stub instance should be created for each new workflow start.
GreetingWorkflow workflow = client.newWorkflowStub(GreetingWorkflow.class);
GreetingWorkflow workflow =
client.newWorkflowStub(
GreetingWorkflow.class,
// At most one instance.
WorkflowOptions.newBuilder()
.setWorkflowId(PERIODIC_WORKFLOW_ID)
.setTaskList(TASK_LIST)
.build());
try {
execution = WorkflowClient.start(workflow::greetPeriodically, "World");
System.out.println("Started " + execution);
Expand Down
Loading