Timeouts
Purpose
Section titled “Purpose”Timeouts provide a crucial mechanism for limiting the maximum execution duration of an entire workflow or individual tasks within it.
Setting timeouts helps prevent workflows or tasks from running indefinitely due to unexpected delays, external service issues, or infinite loops, ensuring resource efficiency and predictable behavior.
How Timeouts Work
Section titled “How Timeouts Work”When a configured timeout duration is reached for a workflow or a task:
- The execution of the workflow or task is abruptly interrupted.
- A standard Timeout Error is raised.
- If this error is not caught by an enclosing
Try
task, the workflow or task transitions immediately to thefaulted
status phase, and the overall workflow execution halts.
Configuration
Section titled “Configuration”Timeouts can be configured at two levels:
- Workflow Level: Set using the top-level
timeout
property in the workflow document. - Task Level: Set using the
timeout
property within a specific task definition.
In both cases, the timeout
property takes an object with the following structure:
after
(duration
, Required): Specifies the duration after which the timeout occurs. The duration itself is defined using an object detailing days, hours, minutes, seconds, or milliseconds.
# Workflow-level timeoutdocument: dsl: '1.0.0' namespace: examples name: workflow-with-timeout version: '1.0.0' timeout: # Applies to the entire workflow execution after: minutes: 30 # Workflow will fault if it runs longer than 30 minutesdo: - step1: # ...
---# Task-level timeoutdo: - callExternalService: call: http with: uri: https://api.externalservice.com/data method: get timeout: # Applies only to the callExternalService task after: seconds: 15 # Task will fault if it takes longer than 15 seconds then: processResult - processResult: # ...
Timeout Error Details
Section titled “Timeout Error Details”When a timeout occurs, the specific error raised must conform to the following:
type
:https://serverlessworkflow.io/spec/1.0.0/errors/timeout
status
:408
(Request Timeout) is recommended.instance
: Should point to the JSON Pointer of the workflow or task that timed out (e.g.,/
,/do/callExternalService
).
This standard error format allows for consistent error handling using Try
tasks specifically targeting timeout
conditions.