Triggering a child Dag
You notice that some of your workflows are using similar components and realize you could separate out common tasks into their own Dag. This should allow you to run those components as necessary without maintaining multiple copies. You decide to execute a child Dag via a task within your current workflow.
The components dag, task, and datetime have been imported for you.
This exercise is part of the course
Introduction to Apache Airflow in Python
Exercise instructions
- Import the operator needed to start a Dag from within your workflow.
- Set the operator to trigger the Dag named
child_pipeline. - Make sure the parent Dag waits for the triggered Dag to complete before continuing.
- Set how frequently the operator checks whether the child Dag has finished.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Import TriggerDagRunOperator
from airflow.providers.standard.operators.trigger_dagrun import ____
@dag(start_date=datetime(2026, 1, 1))
def parent_orchestrator_dag():
# Trigger child_pipeline and wait for it to complete
trigger_child = TriggerDagRunOperator(
task_id="trigger_child_pipeline",
trigger_dag_id="____",
____=True,
____=30,
conf={"source": "s3://my-bucket/raw/"})
validate() >> trigger_child >> post_trigger_summary()
parent_orchestrator_dag()