A FileSensor is a special type of sensor operator in Airflow that waits for a file to appear at a specified location before allowing the workflow to continue.
Click to reveal answer
beginner
How does FileSensor detect the arrival of a file?
FileSensor periodically checks the file system path you specify. When the file exists, it triggers the next task in the workflow.
Click to reveal answer
beginner
Which parameter in FileSensor specifies the file path to watch?
The 'filepath' parameter is used to specify the exact path of the file that FileSensor should wait for.
Click to reveal answer
intermediate
What happens if the file does not arrive within the timeout period in FileSensor?
If the file does not appear before the timeout, the FileSensor task fails and the DAG run is marked as failed unless retries are configured.
Click to reveal answer
intermediate
How can you optimize FileSensor to reduce resource usage?
You can set the 'poke_interval' parameter to increase the time between checks, reducing CPU usage and load on the file system.
Click to reveal answer
What does FileSensor in Airflow primarily do?
ADeletes files from a directory
BProcesses file contents automatically
CUploads files to cloud storage
DWaits for a file to appear before continuing
✗ Incorrect
FileSensor waits for a specific file to appear before allowing the workflow to proceed.
Which parameter tells FileSensor which file to watch?
AfileName
Bfile_path
Cfilepath
Dwatch_file
✗ Incorrect
The correct parameter name is 'filepath' to specify the file location.
What does the 'poke_interval' parameter control in FileSensor?
AThe file permissions
BHow often the sensor checks for the file
CThe file size limit
DThe maximum time to wait for the file
✗ Incorrect
'poke_interval' sets how frequently the sensor checks for the file's presence.
What happens if the file does not appear before the timeout in FileSensor?
AThe task fails and the DAG run fails
BThe task succeeds anyway
CThe file is created automatically
DThe sensor ignores the timeout
✗ Incorrect
If the file does not appear before timeout, the task fails and the DAG run is marked as failed.
Which of these is a good practice to reduce resource use with FileSensor?
ASet poke_interval to a higher value
BSet timeout to zero
CUse multiple FileSensors for the same file
DDisable retries
✗ Incorrect
Increasing poke_interval reduces how often the sensor checks, saving resources.
Explain how FileSensor works in Airflow to detect file arrival.
Think about how Airflow waits for something before moving on.
You got /4 concepts.
Describe how to configure FileSensor to avoid high CPU usage during file waiting.
Consider how often the sensor checks for the file.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of using a FileSensor in Airflow?
easy
A. To upload files to a remote server
B. To delete a file after processing
C. To wait until a specific file appears before running the next task
D. To monitor CPU usage during task execution
Solution
Step 1: Understand FileSensor's role
A FileSensor is designed to pause a task until a file is detected at a given path.
Step 2: Compare options with FileSensor behavior
Only To wait until a specific file appears before running the next task describes waiting for a file's arrival, which matches FileSensor's purpose.
Final Answer:
To wait until a specific file appears before running the next task -> Option C
Quick Check:
FileSensor waits for file = A [OK]
Hint: FileSensor pauses until file exists, then continues [OK]
Common Mistakes:
Confusing FileSensor with file deletion or upload
Thinking it monitors system resources
Assuming it triggers immediately without waiting
2. Which of the following is the correct way to create a FileSensor in Airflow to check for a file named data.csv in /tmp directory with poke_interval=30 and timeout=300?
easy
A. FileSensor(task_id='check_file', filepath='/tmp/data.csv', poke_interval=30, timeout=300)
B. FileSensor(task_id='check_file', path='/tmp/data.csv', poke=30, timeout=300)
C. FileSensor(task_id='check_file', filepath='/tmp/data.csv', interval=30, timeout=300)
D. FileSensor(task_id='check_file', filepath='/tmp/data.csv', poke_interval=30)
Solution
Step 1: Identify correct parameter names
The FileSensor uses 'filepath' for the file path, 'poke_interval' for checking frequency, and 'timeout' for max wait time.
Step 2: Match options with correct parameters
FileSensor(task_id='check_file', filepath='/tmp/data.csv', poke_interval=30, timeout=300) uses correct parameter names and values. FileSensor(task_id='check_file', filepath='/tmp/data.csv', poke_interval=30) misses 'timeout', which is optional but often needed.
Final Answer:
FileSensor(task_id='check_file', filepath='/tmp/data.csv', poke_interval=30, timeout=300) -> Option A
Quick Check:
Use 'filepath' and 'poke_interval' exactly [OK]
Hint: Use 'filepath' and 'poke_interval' parameters exactly [OK]
Common Mistakes:
Using 'path' instead of 'filepath'
Using 'poke' or 'interval' instead of 'poke_interval'
But the task fails immediately with a TypeError. What is the likely cause?
medium
A. task_id cannot contain underscores
B. filepath must be a directory, not a file
C. timeout cannot be set to 300
D. poke_interval should be an integer, not a string
Solution
Step 1: Check parameter types
poke_interval expects an integer number of seconds, not a string.
Step 2: Identify error cause
Setting poke_interval='30' (string) causes TypeError because Airflow expects int.
Final Answer:
poke_interval should be an integer, not a string -> Option D
Quick Check:
poke_interval type must be int [OK]
Hint: poke_interval must be int, not quoted string [OK]
Common Mistakes:
Passing poke_interval as string instead of int
Misunderstanding filepath type requirements
Thinking task_id restrictions cause error
5. You want to create a DAG that waits for multiple files file1.csv and file2.csv to appear in /data before starting processing. Which approach correctly uses FileSensor to achieve this?
hard
A. Create two FileSensor tasks for each file, then set a downstream task that depends on both sensors
B. Create one FileSensor with filepath='/data/file1.csv,/data/file2.csv'
C. Use a single FileSensor with filepath='/data' and wait for directory
D. Create one FileSensor for file1.csv and ignore file2.csv
Solution
Step 1: Understand FileSensor scope
FileSensor waits for one file path; it cannot wait for multiple files at once.
Step 2: Design DAG dependencies
Create two FileSensor tasks, each waiting for one file, then a downstream task that runs after both succeed.
Final Answer:
Create two FileSensor tasks for each file, then set a downstream task that depends on both sensors -> Option A