astronomer.providers.core.sensors.external_task¶
Classes¶
Waits for a different DAG, task group, or task to complete for a specific logical date. |
|
External deployment task sensor Make HTTP call and poll for the response state of externally |
Module Contents¶
- class astronomer.providers.core.sensors.external_task.ExternalTaskSensorAsync(poke_interval=5.0, **kwargs)[source]¶
Bases:
airflow.sensors.external_task.ExternalTaskSensor
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 – The dag_id that contains the task you want to wait for. (templated)
external_task_id – The task_id that contains the task you want to wait for. (templated)
external_task_ids – 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 – The task_group_id that contains the task you want to wait for. (templated)
allowed_states – Iterable of allowed states, default is
['success']
skipped_states – Iterable of states to make this task mark as skipped, default is
None
failed_states – Iterable of failed or dis-allowed states, default is
None
execution_delta – 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 – 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 – 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 – polling period in seconds to check for the status
deferrable – Run sensor in deferrable mode
- is_deprecated = True¶
- post_deprecation_replacement = 'from airflow.sensors.external_task import ExternalTaskSensor'¶
- poke_interval¶
- execute(context)[source]¶
Correctly identify which trigger to execute, and defer execution as expected.
- class astronomer.providers.core.sensors.external_task.ExternalDeploymentTaskSensorAsync(*args, **kwargs)[source]¶
Bases:
airflow.providers.http.sensors.http.HttpSensor
External deployment task sensor Make HTTP call and poll for the response state of externally deployed DAG task to complete. Inherits from HttpSensor, the host should be external deployment url, header with access token
- Parameters:
http_conn_id – The Connection ID to run the sensor against
method – The HTTP request method to use
endpoint – The relative part of the full url
request_params – The parameters to be added to the GET url
headers – The HTTP headers to be added to the GET request
extra_options – Extra options for the ‘requests’ library, see the ‘requests’ documentation (options to modify timeout, ssl, etc.)
tcp_keep_alive – Enable TCP Keep Alive for the connection.
tcp_keep_alive_idle – The TCP Keep Alive Idle parameter (corresponds to
socket.TCP_KEEPIDLE
).tcp_keep_alive_count – The TCP Keep Alive count parameter (corresponds to
socket.TCP_KEEPCNT
)tcp_keep_alive_interval – The TCP Keep Alive interval parameter (corresponds to
socket.TCP_KEEPINTVL
)poke_interval – Time in seconds that the job should wait in between each tries