0
0
Apache Airflowdevops~10 mins

ExternalTaskSensor for cross-DAG dependencies in Apache Airflow - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - ExternalTaskSensor for cross-DAG dependencies
Start ExternalTaskSensor
Check if external DAG run exists
Check external task
v +-----> Back to Check
Sensor completes
Trigger downstream tasks
v +-----> Back to Check
The ExternalTaskSensor waits for a task in another DAG to complete before continuing. It checks repeatedly until the external task finishes, then proceeds.
Execution Sample
Apache Airflow
external_task_sensor = ExternalTaskSensor(
    task_id='wait_for_task',
    external_dag_id='external_dag',
    external_task_id='external_task',
    mode='poke',
    poke_interval=30,
    timeout=600
)
This sensor waits for 'external_task' in 'external_dag' to finish, checking every 30 seconds, timing out after 10 minutes.
Process Table
StepCheck External DAG RunExternal Task StatusActionSensor State
1No run foundN/AWait and retry after 30sWaiting
2Run foundTask runningWait and retry after 30sWaiting
3Run foundTask successComplete sensorSuccess
💡 Sensor completes when external task status is success.
Status Tracker
VariableStartAfter Step 1After Step 2After Step 3
external_dag_run_foundFalseFalseTrueTrue
external_task_statusN/AN/Arunningsuccess
sensor_stateNoneWaitingWaitingSuccess
Key Moments - 2 Insights
Why does the sensor keep waiting even if the external DAG run exists?
Because the external task is still running, not yet successful. The sensor waits until the task status is 'success' as shown in execution_table step 2.
What happens if the external DAG run is not found at all?
The sensor waits and retries checking after the poke interval, as shown in execution_table step 1.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the sensor state at step 2?
AWaiting
BSuccess
CFailed
DSkipped
💡 Hint
Check the 'Sensor State' column at step 2 in the execution_table.
At which step does the sensor complete successfully?
AStep 1
BStep 2
CStep 3
DNever
💡 Hint
Look for 'Complete sensor' action and 'Success' state in the execution_table.
If the external task never succeeds, what will happen to the sensor state?
AIt will become Success anyway
BIt will keep Waiting until timeout
CIt will fail immediately
DIt will skip
💡 Hint
Refer to the sensor behavior in execution_table steps 1 and 2 and the timeout setting in the code sample.
Concept Snapshot
ExternalTaskSensor waits for a task in another DAG to finish.
It checks repeatedly (poke mode) every poke_interval seconds.
If external task is successful, sensor completes.
If no external DAG run or task not done, sensor waits and retries.
Timeout stops sensor after max wait time.
Full Transcript
The ExternalTaskSensor in Airflow is used to wait for a task in a different DAG to complete before continuing. It works by checking if the external DAG run exists and if the external task has succeeded. If the external DAG run is not found or the task is still running, the sensor waits and retries after a set interval. Once the external task is successful, the sensor completes and allows downstream tasks to proceed. This process helps coordinate workflows across multiple DAGs safely and reliably.