airflow.providers.standard.sensors.external_task
¶
Module Contents¶
Classes¶
Operator link for ExternalTaskSensor and ExternalTaskMarker. |
|
Waits for a different DAG, task group, or task to complete for a specific logical date. |
|
Use this operator to indicate that a task on a different DAG depends on this task. |
- class airflow.providers.standard.sensors.external_task.ExternalDagLink[source]¶
Bases:
airflow.models.baseoperatorlink.BaseOperatorLink
Operator link for ExternalTaskSensor and ExternalTaskMarker.
It allows users to access DAG waited with ExternalTaskSensor or cleared by ExternalTaskMarker.
- get_link(operator, *, ti_key)[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.models.baseoperator.BaseOperator) – The Airflow operator object this link is associated to.
ti_key (airflow.models.taskinstancekey.TaskInstanceKey) – TaskInstance ID to return link for.
- Returns
link to external system
- Return type
- class airflow.providers.standard.sensors.external_task.ExternalTaskSensor(*, external_dag_id, external_task_id=None, external_task_ids=None, external_task_group_id=None, allowed_states=None, skipped_states=None, failed_states=None, execution_delta=None, execution_date_fn=None, check_existence=False, poll_interval=2.0, deferrable=conf.getboolean('operators', 'default_deferrable', fallback=False), **kwargs)[source]¶
Bases:
airflow.sensors.base.BaseSensorOperator
Waits for a different DAG, task group, or task to complete for a specific logical date.
If both external_task_group_id and external_task_id are
None
(default), the sensor waits for the DAG. Values for external_task_group_id and external_task_id can’t be set at the same time.By default, the ExternalTaskSensor will wait for the external task to succeed, at which point it will also succeed. However, by default it will not fail if the external task fails, but will continue to check the status until the sensor times out (thus giving you time to retry the external task without also having to clear the sensor).
By default, the ExternalTaskSensor will not skip if the external task skips. To change this, simply set
skipped_states=[TaskInstanceState.SKIPPED]
. Note that if you are monitoring multiple tasks, and one enters error state and the other enters a skipped state, then the external task will react to whichever one it sees first. If both happen together, then the failed state takes priority.It is possible to alter the default behavior by setting states which cause the sensor to fail, e.g. by setting
allowed_states=[DagRunState.FAILED]
andfailed_states=[DagRunState.SUCCESS]
you will flip the behaviour to get a sensor which goes green when the external task fails and immediately goes red if the external task succeeds!Note that
soft_fail
is respected when examining the failed_states. Thus if the external task enters a failed state andsoft_fail == True
the sensor will _skip_ rather than fail. As a result, settingsoft_fail=True
andfailed_states=[DagRunState.SKIPPED]
will result in the sensor skipping if the external task skips. However, this is a contrived example—consider usingskipped_states
if you would like this behaviour. Usingskipped_states
allows the sensor to skip if the target fails, but still enter failed state on timeout. Usingsoft_fail == True
as above will cause the sensor to skip if the target fails, but also if it times out.- Parameters
external_dag_id (str) – The dag_id that contains the task you want to wait for. (templated)
external_task_id (str | None) – The task_id that contains the task you want to wait for. (templated)
external_task_ids (collections.abc.Collection[str] | None) – The list of task_ids that you want to wait for. (templated) 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.external_task_group_id (str | None) – The task_group_id that contains the task you want to wait for. (templated)
allowed_states (collections.abc.Iterable[str] | None) – Iterable of allowed states, default is
['success']
skipped_states (collections.abc.Iterable[str] | None) – Iterable of states to make this task mark as skipped, default is
None
failed_states (collections.abc.Iterable[str] | None) – Iterable of failed or dis-allowed states, default is
None
execution_delta (datetime.timedelta | None) – 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 (Callable | None) – 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).
poll_interval (float) – polling period in seconds to check for the status
deferrable (bool) – Run sensor in deferrable mode
- template_fields = ['external_dag_id', 'external_task_id', 'external_task_ids', 'external_task_group_id'][source]¶
- execute(context)[source]¶
Run on the worker and defer using the triggers if deferrable is set to True.
- class airflow.providers.standard.sensors.external_task.ExternalTaskMarker(*, external_dag_id, external_task_id, logical_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.
logical_date (str | datetime.datetime | None) – 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.