dstandish commented on code in PR #31927:
URL: https://github.com/apache/airflow/pull/31927#discussion_r1230750927
##########
airflow/models/baseoperator.py:
##########
@@ -1838,6 +1839,38 @@ def cross_downstream(
task.set_downstream(to_tasks)
+def chain_sequential(*elements: DependencyMixin | Sequence[DependencyMixin]):
+ """
+ Helper to simplify task dependency definition.
+
+ E.g.: suppose you want precedence like so::
+
+ ╭─op2─╮ ╭─op4─╮
+ op1─┤ ├─├─op5─┤─op7
+ ╰-op3─╯ ╰-op6─╯
+
+ Then you can accomplish like so::
+
+ chain_sequential(
+ op1,
+ [op2, op3],
+ [op4, op5, op6],
+ op7
+ )
+
+ Args:
+ elements: a list of operators / lists of operators
+ """
+ prev_elem = None
+ for curr_elem in elements:
+ if isinstance(curr_elem, EdgeModifier):
+ raise ValueError("Labels are not supported by chain_sequential")
+ if prev_elem is not None:
+ for task in prev_elem:
+ task >> curr_elem
+ prev_elem = curr_elem if isinstance(curr_elem, list) else [curr_elem]
Review Comment:
thanks
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]