-
-
Save vijaykramesh/707262c83429ab2a3f5ee701879813e3 to your computer and use it in GitHub Desktop.
Airflow DAG that locks on enqueued for two of the tasks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime, timedelta | |
import time | |
from airflow import DAG | |
from airflow import logging | |
from airflow.operators.python_operator import PythonOperator | |
default_args = {'owner': 'vijay', | |
'start_date': datetime(2017, 2, 26), | |
'email': ['data.engineers@change.org'], | |
'email_on_failure': True, | |
'email_on_retry': False, | |
'retries': 1, | |
'retry_delay': timedelta(minutes=5), | |
'depends_on_past': False} | |
dag = DAG( | |
'test_lock', | |
schedule_interval='@daily', | |
max_active_runs=1, | |
concurrency=2, | |
default_args=default_args) | |
def some_callable(**kwargs): | |
logging.warn("doing a task on %s" % kwargs['task_instance']) | |
time.sleep(120) | |
t1 = PythonOperator(task_id='t1', | |
python_callable=some_callable, | |
provide_context=True, | |
dag=dag) | |
t2 = PythonOperator(task_id='t2', | |
python_callable=some_callable, | |
provide_context=True, | |
dag=dag) | |
t3 = PythonOperator(task_id='t3', | |
python_callable=some_callable, | |
provide_context=True, | |
dag=dag) | |
t4 = PythonOperator(task_id='t4', | |
python_callable=some_callable, | |
provide_context=True, | |
dag=dag) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
it seems like the first check, when the task instance gets marked State.QUEUED, it also runs self.executor.queue_command(…)
https://github.com/apache/incubator-airflow/blob/master/airflow/jobs.py#L1102
whereas in the second check, if hte task instance gets marked State.QUEUED, it doesn’t https://github.com/apache/incubator-airflow/blob/master/airflow/models.py#L1300
so my initial thought was to make that second check actually queue the command in the executor
but even simpler, if the DagRun.get_running_tasks() check includes State.QUEUED task instances then we never even need to get to the second check (because this will trip https://github.com/apache/incubator-airflow/blob/master/airflow/jobs.py#L1057)
that seems a bit wrong though as then that second check at https://github.com/apache/incubator-airflow/blob/master/airflow/models.py#L1300 could still put things in an odd state