This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 5350cc2  Example xcom update (#17749)
5350cc2 is described below

commit 5350cc2791b780a8ce721e565c235921a63565c1
Author: Lionel <[email protected]>
AuthorDate: Tue Aug 31 19:57:11 2021 +0800

    Example xcom update (#17749)
---
 airflow/example_dags/example_xcom.py | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/airflow/example_dags/example_xcom.py 
b/airflow/example_dags/example_xcom.py
index 03f85d9..de5e14e 100644
--- a/airflow/example_dags/example_xcom.py
+++ b/airflow/example_dags/example_xcom.py
@@ -18,6 +18,7 @@
 
 """Example DAG demonstrating the usage of XComs."""
 from airflow import DAG
+from airflow.operators.bash import BashOperator
 from airflow.operators.python import PythonOperator
 from airflow.utils.dates import days_ago
 
@@ -57,6 +58,14 @@ def puller(**kwargs):
         raise ValueError(f'The two values differ {pulled_value_2} and 
{value_2}')
 
 
+def pull_value_from_bash_push(**kwargs):
+    ti = kwargs['ti']
+    bash_pushed_via_return_value = ti.xcom_pull(key="return_value", 
task_ids='bash_push')
+    bash_manually_pushed_value = ti.xcom_pull(key="manually_pushed_value", 
task_ids='bash_push')
+    print(f"The xcom value pushed by task push via return value is 
{bash_pushed_via_return_value}")
+    print(f"The xcom value pushed by task push manually is 
{bash_manually_pushed_value}")
+
+
 with DAG(
     'example_xcom',
     schedule_interval="@once",
@@ -81,3 +90,28 @@ with DAG(
     )
 
     pull << [push1, push2]
+
+    bash_push = BashOperator(
+        task_id='bash_push',
+        bash_command='echo "bash_push demo"  && '
+        'echo "Manually set xcom value '
+        '{{ ti.xcom_push(key="manually_pushed_value", 
value="manually_pushed_value") }}" && '
+        'echo "value_by_return"',
+    )
+    bash_pull = BashOperator(
+        task_id='bash_pull',
+        bash_command='echo "bash pull demo" && '
+        'echo "The xcom pushed manually is '
+        '"{{ ti.xcom_pull(task_ids="bash_push", key="manually_pushed_value") 
}}" && '
+        'echo "The returned_value xcom is '
+        '"{{ ti.xcom_pull(task_ids="bash_push", key="return_value") }}" && '
+        'echo "finished"',
+        do_xcom_push=False,
+    )
+
+    python_pull_from_bash = PythonOperator(
+        task_id='python_pull_from_bash',
+        python_callable=pull_value_from_bash_push,
+    )
+
+    [bash_pull, python_pull_from_bash] << bash_push

Reply via email to