uranusjr commented on code in PR #33356:
URL: https://github.com/apache/airflow/pull/33356#discussion_r1293000413
##########
airflow/operators/python.py:
##########
@@ -623,6 +623,25 @@ def _iter_serializable_context_keys(self):
yield from self.PENDULUM_SERIALIZABLE_CONTEXT_KEYS
+class BranchPythonVirtualenvOperator(PythonVirtualenvOperator, SkipMixin):
+ """
+ A workflow can "branch" or follow a path after the execution of this task
in a virtualenv.
+ It derives the PythonVirtualenvOperator and expects a Python function that
returns
+ a single task_id or list of task_ids to follow. The task_id(s) returned
+ should point to a task directly downstream from {self}. All other
"branches"
+ or directly downstream tasks are marked with a state of ``skipped`` so that
+ these paths can't move forward. The ``skipped`` states are propagated
+ downstream to allow for the DAG state to fill up and the DAG run's state
+ to be inferred.
+ """
+
+ def execute(self, context: Context) -> Any:
+ branch = super().execute(context)
+ self.log.info("Branch callable return %s", branch)
+ self.skip_all_except(context["ti"], branch)
+ return branch
Review Comment:
Can be a good idea to extract this into a `BranchMixin` so this does not get
duplicated (three times with this addition).
--
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]