What is
In Temporal, timeouts detect application failures. The system can then automatically mitigate these failures through retries. Both major application function primitives, Workflows and Activities, have dedicated timeout configurations and can be configured with a Retry Policy.
Workflow Retry
Workflow timeouts are set when starting the Workflow Execution. Generally do not recommend setting Workflow Timeouts, because Workflows are designed to be long-running and resilient. Instead, setting a Timeout can limit its ability to handle unexpected delays or long-running processes.
Workflow Timeout
//create Workflow stub for YourWorkflowInterface
YourWorkflowInterface workflow1 =
WorkerGreet.greetclient.newWorkflowStub(
GreetWorkflowInterface.class,
WorkflowOptions.newBuilder()
.setWorkflowId(“YourWorkflow”)
.setTaskQueue(WorkerGreet.TASK_QUEUE)
// Set Workflow Timeout duration
.setWorkflowExecutionTimeout(Duration.ofSeconds(10))
// .setWorkflowRunTimeout(Duration.ofSeconds(10))
// .setWorkflowTaskTimeout(Duration.ofSeconds(10))
.build());
Workflow Retry
Use a Retry Policy to retry a Workflow Execution in the event of a failure.
GreetWorkflowInterface workflow1 =
WorkerGreet.greetclient.newWorkflowStub(
GreetWorkflowInterface.class,
WorkflowOptions.newBuilder()
.setWorkflowId(“GreetWF”)
.setTaskQueue(WorkerGreet.TASK_QUEUE)
// Set Workflow Retry Options
.setRetryOptions(RetryOptions.newBuilder()
.build());
Activity Timeout
The following timeouts are available in the Activity Options.
Schedule-To-Close Timeout: is the maximum amount of time allowed for the overall Activity Execution.
Start-To-Close Timeout: is the maximum time allowed for a single Activity Task Execution.
Schedule-To-Start Timeout: is the maximum amount of time that is allowed from when an Activity Task is scheduled to when a Worker starts that Activity Task.
An Activity Execution must have either the Start-To-Close or the Schedule-To-Close Timeout set.
Activity Retry
Activity Executions are automatically associated with a default Retry Policy if a custom one is not provided.
private final ActivityOptions options =
ActivityOptions.newBuilder()
// note that either StartToCloseTimeout or ScheduleToCloseTimeout are
// required when setting Activity options.
.setStartToCloseTimeout(Duration.ofSeconds(5))
.setRetryOptions(
RetryOptions.newBuilder()
.setInitialInterval(Duration.ofSeconds(1))
.setMaximumInterval(Duration.ofSeconds(10))
.build())
.build();
Activity Retry