What is the purpose of the ExternalTaskSensor in Airflow?
ExternalTaskSensor waits for a task in a different DAG to complete before allowing the current DAG to proceed. It helps manage dependencies across DAGs.
Click to reveal answer
beginner
Which parameters are essential to configure an ExternalTaskSensor?
You must specify external_dag_id (the DAG to watch), external_task_id (the task to wait for), and optionally execution_date or use the default to match the current DAG's execution date.
Click to reveal answer
intermediate
How does ExternalTaskSensor handle execution dates by default?
By default, ExternalTaskSensor waits for the task in the external DAG that has the same execution date as the current DAG run.
Click to reveal answer
intermediate
What happens if the external task being waited on fails or never completes?
The ExternalTaskSensor will keep waiting until the task succeeds or the sensor times out or fails based on its timeout or retries settings.
Click to reveal answer
advanced
Can ExternalTaskSensor be used to wait for multiple tasks or DAGs?
ExternalTaskSensor can wait for multiple tasks in the same external DAG (by providing a list to external_task_id). For multiple DAGs, use multiple sensors or custom logic.
Click to reveal answer
What does ExternalTaskSensor primarily do in Airflow?
ASchedules DAG runs automatically
BTriggers a DAG run manually
CMonitors system resource usage
DWaits for a task in another DAG to complete
✗ Incorrect
ExternalTaskSensor waits for a specific task in a different DAG to finish before continuing.
Which parameter tells ExternalTaskSensor which DAG to monitor?
Aexecution_date
Bexternal_task_id
Cexternal_dag_id
Dtask_id
✗ Incorrect
external_dag_id specifies the DAG where the sensor looks for the task.
By default, ExternalTaskSensor matches the external task's execution date with:
AThe current DAG run's execution date
BThe previous DAG run date
CThe current system date
DThe next scheduled DAG run date
✗ Incorrect
It waits for the external task with the same execution date as the current DAG run.
If the external task never completes, what will ExternalTaskSensor do?
AFail immediately
BKeep waiting until timeout or success
CSkip the task
DTrigger the external task
✗ Incorrect
The sensor waits until the task succeeds or the sensor times out or fails.
Can ExternalTaskSensor wait for multiple tasks in different DAGs simultaneously?
ANo, it waits for one task in one DAG only
BYes, it supports multiple tasks natively
CYes, but only if tasks are in the same DAG
DNo, it only waits for tasks in the current DAG
✗ Incorrect
It waits for one or more specific tasks in one external DAG. Multiple waits across DAGs require multiple sensors.
Explain how ExternalTaskSensor helps manage dependencies between different DAGs in Airflow.
Think about how one DAG can pause until another DAG's task finishes.
You got /4 concepts.
Describe what happens if the external task monitored by ExternalTaskSensor fails or never finishes.
Consider sensor behavior on task failure or delay.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of the ExternalTaskSensor in Airflow?
easy
A. To wait for a task in another DAG to complete before proceeding
B. To trigger a DAG run manually
C. To schedule DAGs at specific intervals
D. To monitor system resource usage
Solution
Step 1: Understand the role of ExternalTaskSensor
The ExternalTaskSensor is designed to pause a task until a specified task in a different DAG finishes successfully.
Step 2: Compare with other options
Triggering DAGs, scheduling, and monitoring resources are handled by other components, not ExternalTaskSensor.
Final Answer:
To wait for a task in another DAG to complete before proceeding -> Option A
Quick Check:
ExternalTaskSensor waits for cross-DAG task completion [OK]
Hint: ExternalTaskSensor waits for tasks in other DAGs [OK]
Common Mistakes:
Confusing ExternalTaskSensor with DAG trigger
Thinking it schedules DAGs
Assuming it monitors system resources
2. Which of the following is the correct way to instantiate an ExternalTaskSensor to wait for task 'task_a' in DAG 'dag_1'?
easy
A. ExternalTaskSensor(task_id='wait_task', dag='dag_1', task='task_a')
B. ExternalTaskSensor(task_id='wait_task', dag_id='dag_1', task_id='task_a')
C. ExternalTaskSensor(task_id='wait_task', external_dag='dag_1', external_task='task_a')
D. ExternalTaskSensor(task_id='wait_task', external_dag_id='dag_1', external_task_id='task_a')
Solution
Step 1: Identify correct parameter names
The ExternalTaskSensor requires external_dag_id and external_task_id to specify the DAG and task it waits for.
Step 2: Match parameters with options
Only ExternalTaskSensor(task_id='wait_task', external_dag_id='dag_1', external_task_id='task_a') uses the correct parameter names and syntax.
Final Answer:
ExternalTaskSensor(task_id='wait_task', external_dag_id='dag_1', external_task_id='task_a') -> Option D
Quick Check:
Use external_dag_id and external_task_id parameters [OK]
Hint: Use external_dag_id and external_task_id parameters [OK]
Common Mistakes:
Using wrong parameter names like dag_id or external_dag
But the sensor never finishes even after task_a completes. What is the likely cause?
medium
A. The timeout is too high
B. The sensor's execution_date does not match the external task's execution date
C. The task_id is incorrect
D. The sensor is missing poke_interval
Solution
Step 1: Understand execution_date matching
ExternalTaskSensor waits for the external task with the same execution_date by default.
Step 2: Identify mismatch issue
If the sensor's execution_date differs from the external task's, it will wait forever even if the external task completed.
Final Answer:
The sensor's execution_date does not match the external task's execution date -> Option B
Quick Check:
Execution dates must match for ExternalTaskSensor to succeed [OK]
Hint: Check execution_date alignment between DAGs [OK]
Common Mistakes:
Assuming timeout controls waiting for task completion
Confusing task_id with external_task_id
Thinking poke_interval absence causes hang
5. You want to create a cross-DAG dependency where task_b in dag_2 waits for task_a in dag_1 to succeed, but only for the same execution date. Which configuration ensures this behavior and avoids deadlocks?
hard
A. Use ExternalTaskSensor with external_dag_id='dag_1', external_task_id='task_a', and execution_date_fn=lambda x: x - timedelta(days=1)
B. Use ExternalTaskSensor with external_dag_id='dag_1', external_task_id='task_a', and execution_date_fn=lambda x: x
C. Use ExternalTaskSensor with external_dag_id='dag_1', external_task_id='task_a', and default execution_date matching
D. Use ExternalTaskSensor with external_dag_id='dag_1', external_task_id='task_a', and mode='poke' without execution_date control