Failure Detection - .NET SDK feature guide
This page shows how to do the following:
Workflow timeouts
How to set Workflow timeouts using the Temporal .NET SDK
Each Workflow timeout controls the maximum duration of a different aspect of a Workflow Execution.
Workflow timeouts are set when starting the Workflow Execution.
- Workflow Execution Timeout - restricts the maximum amount of time that a single Workflow Execution can be executed.
- Workflow Run Timeout: restricts the maximum amount of time that a single Workflow Run can last.
- Workflow Task Timeout: restricts the maximum amount of time that a Worker can execute a Workflow Task.
These values can be set in the WorkflowOptions
when calling StartWorkflowAsync
or ExecuteWorkflowAsync
.
Available timeouts are:
- ExecutionTimeout
- RunTimeout
- TaskTimeout
var result = await client.ExecuteWorkflowAsync(
(MyWorkflow wf) => wf.RunAsync(),
new(id: "my-workflow-id", taskQueue: "my-task-queue")
{
WorkflowExecutionTimeout = TimeSpan.FromMinutes(5),
});
Workflow retries
How to set Workflow retries using the Temporal .NET SDK
A Retry Policy can work in cooperation with the timeouts to provide fine controls to optimize the execution experience.
Use a Retry Policy to retry a Workflow Execution in the event of a failure.
Workflow Executions do not retry by default, and Retry Policies should be used with Workflow Executions only in certain situations.
The RetryPolicy
can be set in the WorkflowOptions
when calling StartWorkflowAsync
or ExecuteWorkflowAsync
.
var result = await client.ExecuteWorkflowAsync(
(MyWorkflow wf) => wf.RunAsync(),
new(id: "my-workflow-id", taskQueue: "my-task-queue")
{
RetryPolicy = new() { MaximumInterval = TimeSpan.FromSeconds(10) },
});
Activity timeouts
How to set Activity timeouts using the Temporal .NET SDK
Each Activity timeout controls the maximum duration of a different aspect of an Activity Execution.
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.
These values can be set in the ActivityOptions
when calling ExecuteActivityAsync
.
Available timeouts are:
- ScheduleToCloseTimeout
- ScheduleToStartTimeout
- StartToCloseTimeout
return await Workflow.ExecuteActivityAsync(
(MyActivities a) => a.MyActivity(param),
new() { StartToCloseTimeout = TimeSpan.FromMinutes(5) });
Set an Activity Retry Policy
How to an Activity Retry Policy using the Temporal .NET SDK
A Retry Policy works in cooperation with the timeouts to provide fine controls to optimize the execution experience.
Activity Executions are automatically associated with a default Retry Policy if a custom one is not provided.
To create an Activity Retry Policy in .NET, set the RetryPolicy
on the ActivityOptions
when calling ExecuteActivityAsync
.
return await Workflow.ExecuteActivityAsync(
(MyActivities a) => a.MyActivity(param),
new()
{
StartToCloseTimeout = TimeSpan.FromMinutes(5),
RetryPolicy = new() { MaximumInterval = TimeSpan.FromSeconds(10) },
});