Creating a FileSensor
After reading about FileSensors, you decide to try to implement a basic one to get a feel for some of the parameters used with them. This FileSensor will be designed to make sure a specific datafile is present before continuing.
A FileSensor polls for the file at a regular interval and stops waiting once timeout seconds have elapsed. With mode='reschedule', the worker slot is released between polls.
This exercise is part of the course
Introduction to Apache Airflow in Python
Exercise instructions
- Import the appropriate library to use a FileSensor.
- Set the
precheckreference to the FileSensor object. - Make the FileSensor look for the file "salesdata_ready.csv".
- Set the timeout to 5 minutes.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Import the FileSensor class
from airflow.providers.standard.sensors.filesystem import ____
# Set the file sensor to an alias
precheck = ____(
task_id='check_for_datafile',
# Wait for this file to exist before continuing
filepath='____',
timeout=____,
mode="reschedule"
)