建立 FileSensor
閱讀過 FileSensor 之後,你決定實作一個基本範例,熟悉它會用到的一些參數。這個 FileSensor 會在繼續執行前,確認特定的資料檔存在。
FileSensor 會以固定的間隔輪詢檔案,並在經過 timeout 秒後停止等待。當設定 mode='reschedule' 時,工作槽會在每次輪詢之間被釋放。
本練習屬於課程
Python 中的 Apache Airflow 入門
練習說明
- 匯入可使用 FileSensor 的對應函式庫。
- 將
precheck參照指向 FileSensor 物件。 - 讓 FileSensor 搜尋檔案「salesdata_ready.csv」。
- 將 timeout 設為 5 分鐘。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# 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"
)