airflow.sensors.external_task

Module Contents

Classes

ExternalTaskSensorLink

Operator link for ExternalTaskSensor. It allows users to access

ExternalTaskSensor

Waits for a different DAG or a task in a different DAG to complete for a

ExternalTaskMarker

Use this operator to indicate that a task on a different DAG depends on this task.

Bases: airflow.models.BaseOperatorLink

Operator link for ExternalTaskSensor. It allows users to access DAG waited with ExternalTaskSensor.

name = External DAG[source]

Link to external system.

Note: The old signature of this function was (self, operator, dttm: datetime). That is still supported at runtime but is deprecated.

Parameters
  • operator -- airflow operator

  • ti_key -- TaskInstance ID to return link for

Returns

link to external system

class airflow.sensors.external_task.ExternalTaskSensor(*, external_dag_id, external_task_id=None, external_task_ids=None, allowed_states=None, failed_states=None, execution_delta=None, execution_date_fn=None, check_existence=False, **kwargs)[source]

Bases: airflow.sensors.base.BaseSensorOperator

Waits for a different DAG or a task in a different DAG to complete for a specific logical date.

Parameters
  • external_dag_id (str) -- The dag_id that contains the task you want to wait for

  • external_task_id (Optional[str]) -- The task_id that contains the task you want to wait for. If None (default value) the sensor waits for the DAG

  • external_task_ids (Optional[Collection[str]]) -- The list of task_ids that you want to wait for. If None (default value) the sensor waits for the DAG. Either external_task_id or external_task_ids can be passed to ExternalTaskSensor, but not both.

  • allowed_states (Optional[Iterable[str]]) -- Iterable of allowed states, default is ['success']

  • failed_states (Optional[Iterable[str]]) -- Iterable of failed or dis-allowed states, default is None

  • execution_delta (Optional[datetime.timedelta]) -- time difference with the previous execution to look at, the default is the same logical date as the current task or DAG. For yesterday, use [positive!] datetime.timedelta(days=1). Either execution_delta or execution_date_fn can be passed to ExternalTaskSensor, but not both.

  • execution_date_fn (Optional[Callable]) -- function that receives the current execution's logical date as the first positional argument and optionally any number of keyword arguments available in the context dictionary, and returns the desired logical dates to query. Either execution_delta or execution_date_fn can be passed to ExternalTaskSensor, but not both.

  • check_existence (bool) -- Set to True to check if the external task exists (when external_task_id is not None) or check if the DAG to wait for exists (when external_task_id is None), and immediately cease waiting if the external task or DAG does not exist (default value: False).

template_fields = ['external_dag_id', 'external_task_id', 'external_task_ids'][source]
ui_color = #19647e[source]

Return operator extra links

poke(self, context, session=None)[source]

Function that the sensors defined while deriving this class should override.

get_count(self, dttm_filter, session, states)[source]

Get the count of records against dttm filter and states

Parameters
  • dttm_filter -- date time filter for execution date

  • session -- airflow session object

  • states -- task or dag states

Returns

count of record against the filters

Return type

int

class airflow.sensors.external_task.ExternalTaskMarker(*, external_dag_id, external_task_id, execution_date='{{ logical_date.isoformat() }}', recursion_depth=10, **kwargs)[source]

Bases: airflow.operators.empty.EmptyOperator

Use this operator to indicate that a task on a different DAG depends on this task. When this task is cleared with "Recursive" selected, Airflow will clear the task on the other DAG and its downstream tasks recursively. Transitive dependencies are followed until the recursion_depth is reached.

Parameters
  • external_dag_id (str) -- The dag_id that contains the dependent task that needs to be cleared.

  • external_task_id (str) -- The task_id of the dependent task that needs to be cleared.

  • execution_date (Optional[Union[str, datetime.datetime]]) -- The logical date of the dependent task execution that needs to be cleared.

  • recursion_depth (int) -- The maximum level of transitive dependencies allowed. Default is 10. This is mostly used for preventing cyclic dependencies. It is fine to increase this number if necessary. However, too many levels of transitive dependencies will make it slower to clear tasks in the web UI.

template_fields = ['external_dag_id', 'external_task_id', 'execution_date'][source]
ui_color = #19647e[source]
classmethod get_serialized_fields(cls)[source]

Serialized ExternalTaskMarker contain exactly these fields + templated_fields .

Was this entry helpful?