What is the purpose of the Airflow CLI command airflow tasks test?
It runs a single task instance for a specific DAG and execution date without scheduling. This helps to debug the task by executing it immediately and seeing the output.
Click to reveal answer
beginner
How can you view the logs of a specific task instance using Airflow CLI?
Use the command airflow tasks logs <dag_id> <task_id> <execution_date> to fetch and display the logs for that task instance.
Click to reveal answer
beginner
What does the Airflow CLI command airflow dags list do?
It lists all the DAGs currently available in Airflow. This helps to confirm if your DAG is recognized by Airflow before debugging tasks.
Click to reveal answer
intermediate
Which Airflow CLI command helps you to clear the state of a task instance to rerun it?
The command airflow tasks clear <dag_id> <task_id> --start-date <date> --end-date <date> clears the task state, allowing it to be rerun.
Click to reveal answer
intermediate
Why is it useful to run airflow tasks test instead of triggering the whole DAG?
Running airflow tasks test isolates the task execution, so you can quickly debug and fix issues without waiting for the entire DAG to run or affect downstream tasks.
Click to reveal answer
Which command shows logs for a specific Airflow task instance?
The 'airflow tasks clear' command clears the task state so it can be rerun.
Which command lists all DAGs in Airflow?
Aairflow tasks clear
Bairflow tasks test
Cairflow dags list
Dairflow tasks logs
✗ Incorrect
'airflow dags list' shows all DAGs available in Airflow.
Why is running a single task with airflow tasks test helpful?
AIt isolates the task for quick debugging without running the whole DAG
BIt schedules the entire DAG
CIt clears all task states
DIt shows the DAG structure
✗ Incorrect
It helps debug a single task quickly without running the entire DAG.
Explain how you would debug a failing task in Airflow using the CLI.
Think about running, checking logs, and resetting task state.
You got /4 concepts.
Describe the steps to view logs and rerun a task in Airflow CLI.
Focus on commands for logs, clearing, and testing tasks.
You got /3 concepts.
Practice
(1/5)
1. What is the primary purpose of the Airflow CLI command airflow tasks list DAG_ID?
easy
A. To show logs of a specific task
B. To run all tasks in a DAG immediately
C. To clear all task instances in a DAG
D. To display all tasks in a specific DAG
Solution
Step 1: Understand the command structure
The command airflow tasks list DAG_ID is used to list tasks related to the DAG identified by DAG_ID.
Step 2: Identify the command's function
This command shows all tasks defined in the DAG, helping users see what tasks exist.
Final Answer:
To display all tasks in a specific DAG -> Option D
Quick Check:
List tasks = Display tasks [OK]
Hint: List tasks to see all steps in a DAG quickly [OK]
Common Mistakes:
Confusing 'list' with 'run' to execute tasks
Thinking it clears tasks instead of listing
Assuming it shows logs instead of task names
2. Which of the following is the correct Airflow CLI command to view logs for a task named task1 in DAG example_dag for execution date 2023-01-01T00:00:00?
easy
A. airflow tasks logs example_dag task1 2023-01-01T00:00:00
B. airflow logs example_dag task1 2023-01-01T00:00:00
C. airflow task logs example_dag task1 2023-01-01T00:00:00
D. airflow tasks log example_dag task1 2023-01-01T00:00:00
Solution
Step 1: Recall the correct Airflow CLI syntax for logs
The correct command to view logs is airflow tasks logs DAG_ID TASK_ID EXECUTION_DATE.
Step 2: Match the command with the options
airflow tasks logs example_dag task1 2023-01-01T00:00:00 matches the exact syntax with correct keywords and parameters.
Final Answer:
airflow tasks logs example_dag task1 2023-01-01T00:00:00 -> Option A
-t specifies the task, -s and -e specify start and end dates for clearing task instances.
Final Answer:
It clears all task instances of task1 in example_dag between 2023-01-01 and 2023-01-02 -> Option C
Quick Check:
Clear task instances = It clears all task instances of task1 in example_dag between 2023-01-01 and 2023-01-02 [OK]
Hint: Clear tasks with -t for task and -s/-e for date range [OK]
Common Mistakes:
Confusing clear with run or list commands
Ignoring date range flags -s and -e
Assuming it shows logs instead of clearing
4. You run airflow tasks run example_dag task1 2023-01-01 but get an error saying the task instance does not exist. What is the most likely cause?
medium
A. The command syntax is incorrect and missing required flags
B. The DAG is not loaded or paused, so the task instance is missing
C. The execution date format is wrong and not recognized
D. The task1 does not exist in any DAG
Solution
Step 1: Understand task instance creation
Task instances exist only if the DAG is loaded and active (not paused).
Step 2: Identify why instance might be missing
If the DAG is paused or not loaded, the task instance for the date won't exist, causing the error.
Final Answer:
The DAG is not loaded or paused, so the task instance is missing -> Option B
Quick Check:
Missing instance = DAG paused/not loaded [OK]
Hint: Check DAG status; paused DAGs block task instances [OK]
Common Mistakes:
Assuming syntax error without checking DAG state
Blaming date format without verifying
Thinking task1 is missing from DAG
5. You want to debug a failed task task2 in DAG data_pipeline for execution date 2023-06-15T12:00:00. Which sequence of Airflow CLI commands helps you clear the failed task, rerun it, and then view its logs?