0
0
AirflowHow-ToBeginner ยท 3 min read

How to Clear Task Instance in Airflow: Simple Commands and Examples

To clear a task instance in Airflow, use the airflow tasks clear command with the DAG ID and task ID. This resets the task state so it can be rerun. You can also clear tasks from the Airflow web UI by selecting the task and clicking 'Clear'.
๐Ÿ“

Syntax

The basic syntax to clear a task instance using the Airflow CLI is:

  • airflow tasks clear <dag_id> <task_id> --start-date <start_date> --end-date <end_date>
  • --start-date and --end-date define the date range of the task instances to clear.
  • Use --yes to skip confirmation prompt.
bash
airflow tasks clear <dag_id> <task_id> --start-date YYYY-MM-DD --end-date YYYY-MM-DD [--yes]
๐Ÿ’ป

Example

This example clears the task instance for task process_data in DAG example_dag for the date 2024-06-01. It resets the task state so Airflow can rerun it.

bash
airflow tasks clear example_dag process_data --start-date 2024-06-01 --end-date 2024-06-01 --yes
Output
INFO - Clearing task instances from example_dag.process_data for 2024-06-01 to 2024-06-01 INFO - 1 task instance cleared.
โš ๏ธ

Common Pitfalls

  • Not specifying the correct start-date and end-date can clear unintended task instances.
  • Forgetting --yes causes a confirmation prompt that blocks automation scripts.
  • Clearing tasks without understanding dependencies may cause unexpected DAG behavior.
  • Trying to clear tasks from a paused DAG will not rerun them until the DAG is unpaused.
bash
## Wrong: Missing date range
airflow tasks clear example_dag process_data

## Right: Specify date range and confirm
airflow tasks clear example_dag process_data --start-date 2024-06-01 --end-date 2024-06-01 --yes
๐Ÿ“Š

Quick Reference

Use this cheat sheet to clear task instances quickly:

CommandDescription
airflow tasks clear --start-date YYYY-MM-DD --end-date YYYY-MM-DD --yesClear task instances in date range without prompt
airflow dags unpause Unpause DAG to allow rerun after clearing
Use Airflow UI > Graph View > Select task > ClearClear task instance via web interface
โœ…

Key Takeaways

Use the CLI command airflow tasks clear with correct DAG, task, and date range to reset task instances.
Always specify --start-date and --end-date to avoid clearing wrong tasks.
Add --yes to skip confirmation for automation.
Clearing tasks only resets state; ensure the DAG is unpaused to rerun tasks.
You can also clear tasks easily from the Airflow web UI.