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
)

這篇文章對您有幫助嗎?