Nikhil Kokkula
Nikhil Kokkula

Reputation: 3

Airflow Trigger Rule Task dependencies

In below shown DAG I want to execute task d no matter whether tasks b & c are success or failed, But for task e If tasks b, c & d are success then only it should be triggered. DAG Image

Written below code but it is not working:

with DAG(dag_id='test_dag', default_args=args, schedule_interval=None) as dag:
   t_test = PythonOperator(task_id='test', python_callable=test)
   t_a = PythonOperator(task_id='a', python_callable=a)
   t_b = PythonOperator(task_id='b', python_callable=b)
   t_c = PythonOperator(task_id='c', python_callable=c)
   t_d = PythonOperator(task_id='d', python_callable=d, trigger_rule=TriggerRule.ALL_DONE)
   t_e = PythonOperator(task_id='e', python_callable=e, trigger_rule='all_success')
t_test >> t_a >> [t_b, t_c] >> t_d >> t_e

Upvotes: 0

Views: 341

Answers (1)

Oluwafemi Sule
Oluwafemi Sule

Reputation: 38932

You need to code the branch of your workflow tree in separate statements.

# execute task d no matter whether tasks b & c succeeded or failed
t_test >> t_a >> [t_b, t_c] >> t_d

# execute task e if tasks b, c & d succeeded

t_e << [t_b, t_c, t_d]

Upvotes: 2

Related Questions