You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2018/12/26 19:56:55 UTC

[GitHub] Fokko closed pull request #4365: [AIRFLOW-1684] - Branching based on XCom variable (Docs)

Fokko closed pull request #4365: [AIRFLOW-1684] - Branching based on XCom variable (Docs)
URL: https://github.com/apache/incubator-airflow/pull/4365
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/docs/concepts.rst b/docs/concepts.rst
index eac7a8a7f1..766b69b783 100644
--- a/docs/concepts.rst
+++ b/docs/concepts.rst
@@ -522,6 +522,37 @@ Not like this, where the join task is skipped
 
 .. image:: img/branch_bad.png
 
+The ``BranchPythonOperator`` can also be used with XComs allowing branching
+context to dynamically decide what branch to follow based on previous tasks.
+For example:
+
+.. code:: python
+
+  def branch_func(**kwargs):
+      ti = kwargs['ti']
+      xcom_value = int(ti.xcom_pull(task_ids='start_task'))
+      if xcom_value >= 5:
+          return 'continue_task'
+      else:
+          return 'stop_task'
+
+  start_op = BashOperator(
+      task_id='start_task',
+      bash_command="echo 5",
+      xcom_push=True,
+      dag=dag)
+
+  branch_op = BranchPythonOperator(
+      task_id='branch_task',
+      provide_context=True,
+      python_callable=branch_func,
+      dag=dag)
+
+  continue_op = DummyOperator(task_id='continue_task', dag=dag)
+  stop_op = DummyOperator(task_id='stop_task', dag=dag)
+
+  start_op >> branch_op >> [continue_op, stop_op]
+
 SubDAGs
 =======
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services