PythonSensor

PythonSensor 執行任意可呼叫物件,並等待其返回值為 True。

提示

@task.sensor 裝飾器比經典的 PythonSensor 更推薦用於執行 Python 可呼叫物件來檢查 True 條件。

airflow/example_dags/example_sensor_decorator.py

# Using a sensor operator to wait for the upstream data to be ready.
@task.sensor(poke_interval=60, timeout=3600, mode="reschedule")
def wait_for_upstream() -> PokeReturnValue:
    return PokeReturnValue(is_done=True, xcom_value="xcom_value")

airflow/example_dags/example_sensors.py

t9 = PythonSensor(task_id="success_sensor_python", python_callable=success_callable)

t10 = PythonSensor(
    task_id="failure_timeout_sensor_python", timeout=3, soft_fail=True, python_callable=failure_callable
)

此條目是否有幫助?