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.
Diese Übung ist Teil des Kurses
Einführung in Apache Airflow mit Python
Anleitung zur Übung
- 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.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
# 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"
)