5. Always Clean Up, Never Hide a Failure
Difficulty: Hard · Topic: Trigger rules
The DAG nightly_spark_job runs @daily from 2026-01-01 (no catchup). It rents a cluster for one job:
create_cluster(create_cluster --name nightly-{{ ds_nodash }}), thenrun_job(run_job --cluster nightly-{{ ds_nodash }}).delete_cluster(delete_cluster --name nightly-{{ ds_nodash }}) runs afterrun_jobwhatever happened, so a failed job never leaves a cluster running and billing.notify_failure(notify --dag nightly_spark_job --date {{ ds }}) runs only when one of the three tasks above failed, as soon as it does; otherwise it is skipped.- The DAG run must end
failedwhenever any of the three cluster tasks failed, andsuccessotherwise, so the failure shows up on dashboards.
All four are BashOperator tasks with no retries. You may add other tasks if you need them.
Your DAG file is run in a simulation of the Airflow 3 scheduler against 5 scenarios, including hidden ones.
Sample scenario: The job fails
Deployed 2026-01-10 01:00 UTC, read at 2026-01-10 03:00 UTC.
Expected runs
- Run at 2026-01-10 00:00 UTC: failed. create_cluster success, run_job failed, delete_cluster success, notify_failure success
Hints
Hint 1
trigger_rule="all_done" runs a task once every upstream task has finished, whatever their states.Hint 2
trigger_rule="one_failed" runs a task as soon as one upstream task has failed, without waiting for the rest; if they all finish without a failure, it is skipped.Hint 3
Airflow sets a run's state from its leaf tasks (the ones with nothing downstream). Ifdelete_cluster and notify_failure both succeed, the run succeeds even though the job failed. Airflow's docs fix this with a "watcher": one more task that fails when an upstream task failed.Learn the concepts
- Trigger rules and run state · 5 min read. When a task runs after its upstream tasks fail or skip, and how a run gets its final state.