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
)