airflow.sensors.smart_sensor
¶
Module Contents¶
Classes¶
This class stores a sensor work with decoded context value. It is only used |
|
Wrapper class for the poke work inside smart sensor. It saves |
|
Hold sensor exception information and the type of exception. For possible transient |
|
Smart sensor operators are derived from this class. |
Attributes¶
- class airflow.sensors.smart_sensor.SensorWork(si)[source]¶
This class stores a sensor work with decoded context value. It is only used inside of smart sensor. Create a sensor work based on sensor instance record. A sensor work object has the following attributes: dag_id: sensor_instance dag_id. task_id: sensor_instance task_id. execution_date: sensor_instance execution_date. try_number: sensor_instance try_number poke_context: Decoded poke_context for the sensor task. execution_context: Decoded execution_context. hashcode: This is the signature of poking job. operator: The sensor operator class. op_classpath: The sensor operator class path encoded_poke_context: The raw data from sensor_instance poke_context column. log: The sensor work logger which will mock the corresponding task instance log.
- Parameters
si -- The sensor_instance ORM object.
- class airflow.sensors.smart_sensor.CachedPokeWork[source]¶
Wrapper class for the poke work inside smart sensor. It saves the sensor_task used to poke and recent poke result state. state: poke state. sensor_task: The cached object for executing the poke function. last_poke_time: The latest time this cached work being called. to_flush: If we should flush the cached work.
- class airflow.sensors.smart_sensor.SensorExceptionInfo(exception_info, is_infra_failure=False, infra_failure_retry_window=datetime.timedelta(minutes=130))[source]¶
Hold sensor exception information and the type of exception. For possible transient infra failure, give the task more chance to retry before fail it.
- set_latest_exception(self, exception_info, is_infra_failure=False)[source]¶
This function set the latest exception information for sensor exception. If the exception implies an infra failure, this function will check the recorded infra failure timeout which was set at the first infra failure exception arrives. There is a 6 hours window for retry without failing current run.
- Parameters
exception_info -- Details of the exception information.
is_infra_failure -- If current exception was caused by transient infra failure. There is a retry window _infra_failure_retry_window that the smart sensor will retry poke function without failing current task run.
- class airflow.sensors.smart_sensor.SmartSensorOperator(poke_interval=180, smart_sensor_timeout=60 * 60 * 24 * 7, soft_fail=False, shard_min=0, shard_max=100000, poke_timeout=6.0, *args, **kwargs)[source]¶
Bases:
airflow.models.BaseOperator
,airflow.models.SkipMixin
Smart sensor operators are derived from this class.
Smart Sensor operators keep refresh a dictionary by visiting DB. Taking qualified active sensor tasks. Different from sensor operator, Smart sensor operators poke for all sensor tasks in the dictionary at a time interval. When a criteria is met or fail by time out, it update all sensor task state in task_instance table
- Parameters
soft_fail -- Set to true to mark the task as SKIPPED on failure
poke_interval -- Time in seconds that the job should wait in between each tries.
smart_sensor_timeout -- Time, in seconds before the internal sensor job times out if poke_timeout is not defined.
shard_min -- shard code lower bound (inclusive)
shard_max -- shard code upper bound (exclusive)
poke_timeout -- Time, in seconds before the task times out and fails.
- flush_cached_sensor_poke_results(self)[source]¶
Flush outdated cached sensor states saved in previous loop.
- poke(self, sensor_work)[source]¶
Function that the sensors defined while deriving this class should override.