zhongjiajie commented on a change in pull request #4779: [AIRFLOW-3958] List
tasks upstream work in chain
URL: https://github.com/apache/airflow/pull/4779#discussion_r287934261
##########
File path: airflow/utils/helpers.py
##########
@@ -150,19 +151,50 @@ def as_flattened_list(iterable):
def chain(*tasks):
- """
+ r"""
Given a number of tasks, builds a dependency chain.
+ Support mix airflow.models.BaseOperator and
List[airflow.models.BaseOperator].
+ If you want to chain between two List[airflow.models.BaseOperator], have to
+ make sure they have same length.
- chain(task_1, task_2, task_3, task_4)
+ chain(t1, [t2, t3], [t4, t5], t6)
is equivalent to
- task_1.set_downstream(task_2)
- task_2.set_downstream(task_3)
- task_3.set_downstream(task_4)
+ / -> t2 -> t4 \
+ t1 -> t6
+ \ -> t3 -> t5 /
+
+ t1.set_downstream(t2)
+ t1.set_downstream(t3)
+ t2.set_downstream(t4)
+ t3.set_downstream(t5)
+ t4.set_downstream(t6)
+ t5.set_downstream(t6)
+
+ :param tasks: List of tasks or List[airflow.models.BaseOperator] to set
dependencies
+ :type tasks: List[airflow.models.BaseOperator] or
airflow.models.BaseOperator
"""
- for up_task, down_task in zip(tasks[:-1], tasks[1:]):
- up_task.set_downstream(down_task)
+ from airflow.models import BaseOperator
Review comment:
@kaxil I try put import in the top file, but it CI failed. And then Got
advice from @BasPH to put `import` inside functions to pass CI
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services