4.6.7. Workflow Timeout

In this chapter, you’ll learn how to set a timeout for workflows and steps.

Configure 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 run. Once the specified time is passed and the workflow is still running, the workflow is considered failed and an error is thrown.

Note

Timeout doesn't stop the execution of a running step. The timeout only affects the status of the workflow and its result.

For example:

src/workflows/hello-world.ts
15}16
17const myWorkflow = createWorkflow<18  {},19  WorkflowOutput20>({21  name: "hello-world",22  timeout: 2, // 2 seconds23}, function () {24  const str1 = step1()25
26  return {27    message: str1,28  }29})30
31export default myWorkflow

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.

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

For example:

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

The step’s configuration object accepts a timeout property, whose value is a number indicating the timeout in 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?