airflow.sensors.base
¶
Module Contents¶
Classes¶
Sensor operators are derived from this class and inherit these attributes. |
Functions¶
|
Class Decorator for child classes of BaseSensorOperator to indicate |
- class airflow.sensors.base.BaseSensorOperator(*, poke_interval: float = 60, timeout: float = 60 * 60 * 24 * 7, soft_fail: bool = False, mode: str = 'poke', exponential_backoff: bool = False, **kwargs)[source]¶
Bases:
airflow.models.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 (float) – Time in seconds that the job should wait in between each tries
timeout (float) – Time, in seconds before the task times out and fails.
mode (str) – How the sensor operates. Options are:
{ poke | reschedule }
, default ispoke
. When set topoke
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 toreschedule
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
- execution_fields = ['poke_interval', 'retries', 'execution_timeout', 'timeout', 'email', 'email_on_retry',...[source]¶
- poke(self, context: Dict) bool [source]¶
Function that the sensors defined while deriving this class should override.
- is_smart_sensor_compatible(self)[source]¶
Return if this operator can use smart service. Default False.
- register_in_sensor_service(self, ti, context)[source]¶
Register ti in smart sensor service
- Parameters
ti – Task instance object.
context – TaskInstance template context from the ti.
- Returns
boolean
- get_poke_context(self, context)[source]¶
Return a dictionary with all attributes in poke_context_fields. The poke_context with operator class can be used to identify a unique sensor job.
- Parameters
context – TaskInstance template context.
- Returns
A dictionary with key in poke_context_fields.
- get_execution_context(self, context)[source]¶
Return a dictionary with all attributes in execution_fields. The execution_context include execution requirement for each sensor task such as timeout setup, email_alert setup.
- Parameters
context – TaskInstance template context.
- Returns
A dictionary with key in execution_fields.
- execute(self, context: Dict) Any [source]¶
This is the main method to derive when creating an operator. Context is the same dictionary used as when rendering jinja templates.
Refer to get_template_context for more context.
- airflow.sensors.base.poke_mode_only(cls)[source]¶
Class Decorator for child classes of BaseSensorOperator to 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 (type) – BaseSensor class to enforce methods only use ‘poke’ mode.