6.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:

src/workflows/hello-world.ts
12)13
14const myWorkflow = createWorkflow({15  name: "hello-world",16  timeout: 2, // 2 seconds17}, function () {18  const str1 = step1()19
20  return new WorkflowResponse({21    message: str1,22  })23})24
25export default myWorkflow

This workflow's executions fail if they run longer than two seconds.

Tip: A workflow’s timeout error is returned in the 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.

Note: As mentioned in the previous section, the timeout doesn't stop the execution of the step. It only affects the step's status and output.

The step’s configuration object accepts a timeout property, whose value is a number indicating the timeout in seconds.

For example:

Code
1const step1 = createStep(2  {3    name: "step-1",4    timeout: 2, // 2 seconds5  },6  async () => {7    // ...8  }9)

This step's executions fail if they run longer than two seconds.

Tip: A step’s timeout error is returned in the errors property of the workflow’s execution, as explained in this chapter . The error’s name is TransactionStepTimeoutError .
Was this chapter helpful?