XCom with return values
📖 Scenario: You are working with Apache Airflow to automate tasks. You want to pass data between tasks using XComs, which allow tasks to share small pieces of information.Imagine you have two tasks: one that generates a number, and another that uses that number to print a message.
🎯 Goal: Build a simple Airflow DAG with two Python tasks. The first task returns a value using XCom. The second task reads that value and prints it.
📋 What You'll Learn
Create a Python function called
generate_number that returns the integer 42.Create a Python function called
print_number that accepts ti as a parameter and pulls the XCom value from generate_number task.Create a DAG named
xcom_return_value_dag with two tasks: task_generate and task_print.Set
task_generate to run generate_number and task_print to run print_number.Set
task_generate to run before task_print.Print the pulled XCom value inside
print_number.💡 Why This Matters
🌍 Real World
In real Airflow workflows, tasks often need to share data like IDs, statuses, or results. XComs let you pass this data easily between tasks.
💼 Career
Understanding XComs is essential for Airflow users and DevOps engineers who automate workflows and need tasks to communicate with each other.
Progress0 / 4 steps