-
-
Save vijaykramesh/707262c83429ab2a3f5ee701879813e3 to your computer and use it in GitHub Desktop.
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) |
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
with more verbose logging it seems like the second check is failing, but the status doesn't get moved back correctly?
Note that if I stop the scheduler and restart it it will pick up the enqueued tasks correctly.