Sub topic 11
Retries and timeouts
This chapter assumes you can build a multi-task job with dependencies and know that a run is one execution of a job. Retries and timeouts decide what happens when a task fails or runs too long. Both are set per task, not per job.
Retries
A retry policy tells Databricks to start a failed task again, on the same run, before it gives up. Three fields control it:
max_retries: how many times to retry after the first failure. The default is 0, so a task is not retried unless you ask.min_retry_interval_millis: the minimum wait between the end of a failed attempt and the start of the next one.retry_on_timeout: whether a timed-out attempt counts as a failure that can be retried. The default is false.
The job definition from earlier in this tutorial retries only ingest:
{
"task_key": "ingest",
"job_cluster_key": "etl_cluster",
"notebook_task": {"notebook_path": "/Workspace/Shared/ingest"},
"max_retries": 2,
"min_retry_interval_millis": 60000
}Here ingest can run up to three times in total: the first attempt plus two retries, each at least 60 seconds apart. The downstream transform task waits the whole time. It starts only if one attempt succeeds. If all three attempts fail, ingest is marked failed and its dependents do not run, unless their run_if rule says otherwise.
Timeouts
A timeout is a limit on how long one task attempt may run. Set it with timeout_seconds. When an attempt exceeds the limit, Databricks cancels it and marks it as timed out. The default is 0, which means no limit. You can also set a job-level timeout in the job settings, which limits the whole run.
Without a timeout, a hung task keeps the cluster busy and blocks the next scheduled run if max_concurrent_runs is 1. Pick a value comfortably above the normal duration, such as two or three times the usual runtime.
{
"task_key": "ingest",
"notebook_task": {"notebook_path": "/Workspace/Shared/ingest"},
"timeout_seconds": 1800,
"max_retries": 2,
"retry_on_timeout": true,
"min_retry_interval_millis": 60000
}Each attempt gets its own 30 minutes. With retry_on_timeout set to true, a timed-out attempt triggers a retry. With the default, a timeout fails the task right away.
Common errors
- Retrying non-idempotent work. An idempotent task gives the same result when run twice. If
ingestappends rows, a retry after a partial write can duplicate data. Use overwrite,MERGE, or a run-specific path. - Setting no timeout and finding a stuck run hours later.
- Expecting a timeout to retry. It does not unless
retry_on_timeoutis true. - Setting retries on every task. Retrying a deterministic bug three times only delays the alert. Reserve retries for flaky steps such as network reads.
Exercise
A task has maxretries set to 3 and timeoutseconds set to 600, and retryontimeout is left at its default. An attempt hangs. What happens, and what is the maximum number of attempts if every attempt fails normally?
Show answer
The hung attempt is cancelled after 600 seconds and the task fails without a retry, because retryontimeout defaults to false. If every attempt fails normally (not by timeout), the task runs 4 times: the first attempt plus 3 retries.