Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Airflow: Only allow one instance of task

Tags:

airflow

DAG Tree view

Is there a way specify that a task can only run once concurrently? So in the tree above where DAG concurrency is 4, Airflow will start task 4 instead of a second instance of task 2?

This DAG is a little special because there is no order between the tasks. These tasks are independent but related in purpose and therefore kept in one DAG so as to new create an excessive number of single task DAGs.

max_active_runs is 2 and dag_concurrency is 4. I would like it start all 4 tasks and only start a task in next if same task in previous run is done.

like image 983
Wessi Avatar asked Sep 01 '25 11:09

Wessi


2 Answers

I may have mis-understood your question, but I believe you are wanting to have all the tasks in a single dagrun finish before the tasks begin in the next dagrun. So a DAG will only execute once the previous execution is complete.

If that is the case, you can make use of the max_active_runs parameter of the dag to limit how many running concurrent instances of a DAG there are allowed to be.

More information here (refer to the last dotpoint): https://airflow.apache.org/faq.html#why-isn-t-my-task-getting-scheduled

max_active_runs defines how many running concurrent instances of a DAG there are allowed to be.

like image 106
Josh Avatar answered Sep 04 '25 08:09

Josh


Airflow operator documentation describes argument task_concurrency. Just set it to one.

like image 33
Jussi Kujala Avatar answered Sep 04 '25 10:09

Jussi Kujala