简体   繁体   中英

How to set trigger_rule on specific tasks in Airflow

I would like to set trigger rules on specific tasks.

For instance, if i have the following dependencies in my dag:

task_init >> task_1 >> task_2

  • task_init needs to be ok to run task_1
  • task_2 can run only if task_init is ok but does not pay attention to task_2

How can i do it?

You don't need trigger rules for what you're describing:

task_init >> [task_1, task_2]

By default, tasks in Airflow run if the previous task completed successfully. So in this code, task_init starts, and tasks task_1 and task_2 only start after task_init completed successfully. A list ( [] ) can be used to group tasks together and dependencies can be set between a single task and a list of tasks.

You can also view this in the Airflow Graph View:

在此处输入图像描述

Read more about task dependencies here:

task_init >> task_1 >> task_2
task_init >> task_2

This will resolve the problem. More information can be found here https://stackoverflow.com/a/66866925

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM