How to restart a stuck Airflow DAG
Occasionally, Airflow DAGs get stuck in the running state but don’t want to run any tasks. From my observations, it happens mostly when we clear many DAG runs in one DAG because we want to reprocess a large number of tasks.
To avoid this problem, I suggest using the backfill command to restart only a small subset of DAGS. For example, a week of work, wait until it finishes, and restarting another batch.
Anyway, what to do when it is too late, and we have already ended up in a situation when everything is running
, but nothing actually wants to run.
The first thing we can do is using the airflow clear
command to remove the current state of those DAG runs. We can specify the date range using the -s
and -e
parameters:
1
airflow clear -s 2020-01-01 -e 2020-01-07 dag_id
Would you like to help fight youth unemployment while getting mentoring experience?
Develhope is looking for tutors (part-time, freelancers) for their upcoming Data Engineer Courses.
The role of a tutor is to be the point of contact for students, guiding them throughout the 6-month learning program. The mentor supports learners through 1:1 meetings, giving feedback on assignments, and responding to messages in Discord channels—no live teaching sessions.
Expected availability: 15h/week. You can schedule the 1:1 sessions whenever you want, but the sessions must happen between 9 - 18 (9 am - 6 pm) CEST Monday-Friday.
Check out their job description.
(free advertisement, no affiliate links)
When that is not enough, we need to use the Airflow UI. In the menu, click the ‘Browse” tab, and open the ‘DAG Runs’ view.
On this page, we should find the DAG runs that don’t want to run, select them, and click the ‘With selected’ menu option. In the new menu, we click the ‘Delete’ command.
After that, Airflow should recreate the missing task instances and perhaps starts to execute the code.
You may also like
- How to trigger an Airflow DAG from another DAG
- How to use xcom_pull to get a variable from another DAG
- Use LatestOnlyOperator to skip some tasks while running a backfill in Airflow
- How to retrieve the statuses of the recent DAG executions from Airflow database
- How to deal with the jinja2 TemplateNotFound error in Airflow