Timeout allows you to set a maximum duration for a task run.

What is timeout

If the task run exceeds the specified duration, Kestra will automatically stop the task run and mark it as failed. This is useful for tasks that may hang and run indefinitely.

Timeout is often used as a cost control mechanism for cloud-based workflows. Imagine a Snowflake query or an AWS Batch job that runs for hours leading to unexpected costs. By setting a timeout, you can ensure that the task run will not exceed a certain duration.

Format

Similar to durations in retries, timeouts use the ISO 8601 Durations format. Below are some examples:

namedescription
PT0.250S250 milliseconds delay
PT2S2 seconds delay
PT1M1 minute delay
PT3.5H3 hours and a half delay

Example

In this example, the costly_query task will sleep for 10 seconds, but the timeout is set to 5 seconds, leading to a failed task run.

yaml
id: timeout
namespace: company.team
description: This flow will always fail because of a timeout.

tasks:
  - id: costly_query
    type: io.kestra.plugin.scripts.shell.Commands
    taskRunner:
      type: io.kestra.plugin.core.runner.Process
    commands:
      - sleep 10
    timeout: PT5S

Was this page helpful?