TimeDeltaSensor

使用 TimeDeltaSensor 在特定时间后结束传感。

airflow/example_dags/example_sensors.py[源代码]

t0 = TimeDeltaSensor(task_id="wait_some_seconds", delta=datetime.timedelta(seconds=2))

TimeDeltaSensorAsync

使用 TimeDeltaSensorAsync 在特定时间后结束传感。 它是操作符的异步版本,需要触发器运行。

airflow/example_dags/example_sensors.py[源代码]

t0a = TimeDeltaSensorAsync(task_id="wait_some_seconds_async", delta=datetime.timedelta(seconds=2))

TimeSensor

使用 TimeSensor 在指定时间后结束传感。

airflow/example_dags/example_sensors.py[源代码]

t1 = TimeSensor(
    task_id="fire_immediately", target_time=datetime.datetime.now(tz=datetime.timezone.utc).time()
)

t2 = TimeSensor(
    task_id="timeout_after_second_date_in_the_future",
    timeout=1,
    soft_fail=True,
    target_time=(datetime.datetime.now(tz=datetime.timezone.utc) + datetime.timedelta(hours=1)).time(),
)

TimeSensorAsync

使用 TimeSensorAsync 在指定时间后结束传感。 它是操作符的异步版本,需要触发器运行。

airflow/example_dags/example_sensors.py[源代码]

t1a = TimeSensorAsync(
    task_id="fire_immediately_async", target_time=datetime.datetime.now(tz=datetime.timezone.utc).time()
)

t2a = TimeSensorAsync(
    task_id="timeout_after_second_date_in_the_future_async",
    timeout=1,
    soft_fail=True,
    target_time=(datetime.datetime.now(tz=datetime.timezone.utc) + datetime.timedelta(hours=1)).time(),
)

DayOfWeekSensor

使用 DayOfWeekSensor 感知星期几。

airflow/example_dags/example_sensors.py[源代码]

t11 = DayOfWeekSensor(
    task_id="week_day_sensor_failing_on_timeout", timeout=3, soft_fail=True, week_day=WeekDay.MONDAY
)

此条目是否有帮助?