BaşlayınÜcretsiz Başlayın

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.

Bu egzersiz

Python ile Apache Airflow'a Giriş

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Import the appropriate library to use a FileSensor.
  • Set the precheck reference to the FileSensor object.
  • Make the FileSensor look for the file "salesdata_ready.csv".
  • Set the timeout to 5 minutes.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

# 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"
)
Kodu Düzenle ve Çalıştır