How to restart a stuck Airflow DAG

This article is a part of my "100 data engineering tutorials in 100 days" challenge. (99/100)

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

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.

Did you enjoy reading this article?
Would you like to learn more about software craft in data engineering and MLOps?

Subscribe to the newsletter or add this blog to your RSS reader (does anyone still use them?) to get a notification when I publish a new essay!

Newsletter

Do you enjoy reading my articles?
Subscribe to the newsletter if you don't want to miss the new content, business offers, and free training materials.

Bartosz Mikulski

Bartosz Mikulski

  • Data/MLOps engineer by day
  • DevRel/copywriter by night
  • Python and data engineering trainer
  • Conference speaker
  • Contributed a chapter to the book "97 Things Every Data Engineer Should Know"
  • Twitter: @mikulskibartosz
Newsletter

Do you enjoy reading my articles?
Subscribe to the newsletter if you don't want to miss the new content, business offers, and free training materials.