airflow.sensors.base

Module Contents

Classes

PokeReturnValue

Optional return value for poke methods.

BaseSensorOperator

Sensor operators are derived from this class and inherit these attributes.

Functions

poke_mode_only(cls)

Decorate a subclass of BaseSensorOperator with poke.

class airflow.sensors.base.PokeReturnValue(is_done, xcom_value=None)[source]

Optional return value for poke methods.

Sensors can optionally return an instance of the PokeReturnValue class in the poke method. If an XCom value is supplied when the sensor is done, then the XCom value will be pushed through the operator return value. :param is_done: Set to true to indicate the sensor can stop poking. :param xcom_value: An optional XCOM value to be returned by the operator.

__bool__()[source]
class airflow.sensors.base.BaseSensorOperator(*, poke_interval=60, timeout=conf.getfloat('sensors', 'default_timeout'), soft_fail=False, mode='poke', exponential_backoff=False, max_wait=None, silent_fail=False, **kwargs)[source]

Bases: airflow.models.baseoperator.BaseOperator, airflow.models.skipmixin.SkipMixin

Sensor operators are derived from this class and inherit these attributes.

Sensor operators keep executing at a time interval and succeed when a criteria is met and fail if and when they time out.

Parameters
  • soft_fail (bool) – Set to true to mark the task as SKIPPED on failure

  • poke_interval (datetime.timedelta | float) – Time that the job should wait in between each try. Can be timedelta or float seconds.

  • timeout (datetime.timedelta | float) – Time elapsed before the task times out and fails. Can be timedelta or float seconds. This should not be confused with execution_timeout of the BaseOperator class. timeout measures the time elapsed between the first poke and the current time (taking into account any reschedule delay between each poke), while execution_timeout checks the running time of the task (leaving out any reschedule delay). In case that the mode is poke (see below), both of them are equivalent (as the sensor is never rescheduled), which is not the case in reschedule mode.

  • mode (str) – How the sensor operates. Options are: { poke | reschedule }, default is poke. When set to poke the sensor is taking up a worker slot for its whole execution time and sleeps between pokes. Use this mode if the expected runtime of the sensor is short or if a short poke interval is required. Note that the sensor will hold onto a worker slot and a pool slot for the duration of the sensor’s runtime in this mode. When set to reschedule the sensor task frees the worker slot when the criteria is not yet met and it’s rescheduled at a later time. Use this mode if the time before the criteria is met is expected to be quite long. The poke interval should be more than one minute to prevent too much load on the scheduler.

  • exponential_backoff (bool) – allow progressive longer waits between pokes by using exponential backoff algorithm

  • max_wait (datetime.timedelta | float | None) – maximum wait interval between pokes, can be timedelta or float seconds

  • silent_fail (bool) – If true, and poke method raises an exception different from AirflowSensorTimeout, AirflowTaskTimeout, AirflowSkipException and AirflowFailException, the sensor will log the error and continue its execution. Otherwise, the sensor task fails, and it can be retried based on the provided retries parameter.

property reschedule[source]

Define mode rescheduled sensors.

ui_color: str = '#e6f1f2'[source]
valid_modes: Iterable[str] = ['poke', 'reschedule'][source]
deps[source]
poke(context)[source]

Override when deriving this class.

execute(context)[source]

Derive when creating an operator.

Context is the same dictionary used as when rendering jinja templates.

Refer to get_template_context for more context.

resume_execution(next_method, next_kwargs, context)[source]

Call this method when a deferred task is resumed.

prepare_for_execution()[source]

Lock task for execution to disable custom action in __setattr__ and return a copy.

classmethod get_serialized_fields()[source]

Stringified DAGs and operators contain exactly these fields.

airflow.sensors.base.poke_mode_only(cls)[source]

Decorate a subclass of BaseSensorOperator with poke.

Indicate that instances of this class are only safe to use poke mode.

Will decorate all methods in the class to assert they did not change the mode from ‘poke’.

Parameters

cls – BaseSensor class to enforce methods only use ‘poke’ mode.

Was this entry helpful?