4.8.10. Workflow Timeout
In this chapter, you’ll learn how to set a timeout for workflows and steps.
What is a Workflow Timeout?#
By default, a workflow doesn’t have a timeout. It continues execution until it’s finished or an error occurs.
You can configure a workflow’s timeout to indicate how long the workflow can execute. If a workflow's execution time passes the configured timeout, it is failed and an error is thrown.
Timeout Doesn't Stop Step Execution#
Configuring a timeout doesn't stop the execution of a step in progress. The timeout only affects the status of the workflow and its result.
Configure Workflow Timeout#
The createWorkflow function can accept a configuration object instead of the workflow’s name.
In the configuration object, you pass a timeout property, whose value is a number indicating the timeout in seconds.
For example:
)
const myWorkflow = createWorkflow({
name: "hello-world",
timeout: 2, // 2 seconds
}, function () {
const str1 = step1()
return new WorkflowResponse({
message: str1,
})
})
export default myWorkflow
This workflow's executions fail if they run longer than two seconds.
errors property of the workflow’s execution, as explained in this chapter. The error’s name is TransactionTimeoutError.Configure Step Timeout#
Alternatively, you can configure the timeout for a step rather than the entire workflow.
The step’s configuration object accepts a timeout property, whose value is a number indicating the timeout in seconds.
For example:
const step1 = createStep(
{
name: "step-1",
timeout: 2, // 2 seconds
},
async () => {
// ...
}
)
This step's executions fail if they run longer than two seconds.
errors property of the workflow’s execution, as explained in this chapter. The error’s name is TransactionStepTimeoutError.