0

In order to run Python scripts inside virtualenv when scheduled using Apache Airflow, the BashOperator is used.

For example,

task_a = BashOperator(
    task_id='task_a',
    bash_command='/path/to/virtualenv/bin/python /path/to/script_a.py'),
    dag=dag)

task_b = BashOperator(
    task_id='task_b',
    bash_command='/path/to/virtualenv/bin/python /path/to/script_b.py'),
    dag=dag)

In this case, how can we pass data between task_a and task_b, like how you could when using Xcom when the PythonOperator is used?

1 Answer 1

2

Pass {{ ti.xcom_pull(task_ids='task_a') }} as an argument to your script in task_b. Remember only last line of the output of BashOperator is pushed to Xcom.

task_a = BashOperator(
    task_id='task_a',
    bash_command='/path/to/virtualenv/bin/python /path/to/script_a.py'),
    dag=dag)

task_b = BashOperator(
    task_id='task_b',
    bash_command="/path/to/virtualenv/bin/python /path/to/script_b.py {{ ti.xcom_pull(task_ids='task_a') }}"),
    dag=dag)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.