Triggers

Airflow trigger used by the provider’s deferrable waits: it polls the status of a YellowDog work requirement, worker pool or compute requirement from the triggerer until a target state, a failure state or a deadline is reached.

yellowdog_provider.triggers.yellowdog_triggers.KillAction

What a YellowDogStateTrigger does to its resource when the deferred task is killed by a user (see YellowDogStateTrigger.on_kill()).

alias of Literal[‘cancel_work_requirement’, ‘terminate_worker_pool’]

class yellowdog_provider.triggers.yellowdog_triggers.ResourceKind(*values)[source]

Bases: StrEnum

The kinds of YellowDog resource a YellowDogStateTrigger polls.

COMPUTE_REQUIREMENT = 'compute_requirement'
WORKER_POOL = 'worker_pool'
WORK_REQUIREMENT = 'work_requirement'
class yellowdog_provider.triggers.yellowdog_triggers.YellowDogStateTrigger(*, connection_id: str, kind: ResourceKind | str, resource_id: str, target_states: Sequence[str | Enum], failure_states: Sequence[str | Enum], poke_interval: float, end_time: float, kill_action: Literal['cancel_work_requirement', 'terminate_worker_pool'] | None = None)[source]

Bases: BaseTrigger

Poll a YellowDog resource’s status every poke_interval seconds, and fire a single event when it reaches a target state, a failure state, or the end_time deadline. The first check is made straight away, and one is always made at the deadline before timing out.

States are the status enums’ .value strings, so that the trigger can be serialized. The Airflow connection is fetched once per run, in the event loop (with BaseHook.aget_connection); each check then runs in a worker thread with its own hook (and client) built from that connection, created and closed for that check, so worker threads never look the connection up themselves (in the triggerer, that would use the supervisor’s comms channel from outside the event loop, which Airflow 3.1 does not tolerate). If the connection lookup fails, the trigger ends with an "error" event. Errors from the check are not raised. Up to MAX_CONSECUTIVE_TRANSIENT_ERRORS consecutive transient errors (see is_transient_error()) are logged and polling continues; the next one, or any other error, ends the trigger with an "error" event, and the deferred task fails when it resumes. If the deadline passes after a transient error, the event is "timeout" (or "error" if no state was ever read).

The event payload is a dict with the keys status ("target", "failure", "timeout" or "error"), kind (a ResourceKind value), resource_id, state (the last status value read, or None) and message; "error" events also have error_type (the exception’s class name).

Parameters:
  • connection_id – the Airflow connection ID for YellowDog

  • kind – the kind of resource

  • resource_id – the resource’s YellowDog ID

  • target_states – the statuses to wait for (status enum members or their values)

  • failure_states – the statuses that end the wait as a failure (status enum members or their values)

  • poke_interval – seconds between checks

  • end_time – the deadline, in seconds since the epoch (wall clock, because the trigger may be resumed in another process)

  • kill_action – what to do to the resource if the deferred task is killed by a user (marked failed or succeeded, or cleared): "cancel_work_requirement" cancels a work requirement, aborting its running tasks; "terminate_worker_pool" shuts down a worker pool and terminates its compute requirement; None (the default) does nothing. The action is best-effort (failures, including failing to fetch the connection, are logged). Airflow calls the trigger’s on_kill from Airflow 3.3 (verified on 3.4); on earlier versions (3.1, 3.2) a deferred task killed by a user is not cleaned up. Airflow bounds on_kill by [triggerer] on_kill_timeout (default 30 seconds); an action that takes longer is abandoned.

Raises:

YellowDogArgumentError – if a state is not a status of the resource’s kind, or kill_action is unknown or does not suit kind

connection_id: str
end_time: float
failure_states: tuple[str, ...]
kill_action: KillAction | None
kind: ResourceKind
async on_kill() → None[source]

Run the kill_action, if any, when the deferred task is killed by a user. Called by Airflow 3.3 and later (verified on 3.4); not by Airflow 3.1 or 3.2. Best-effort: failures are logged, never raised.

poke_interval: float
resource_id: str
async run() → AsyncIterator[TriggerEvent][source]

Poll until a target or failure state, the deadline or an error.

serialize() → tuple[str, dict[str, Any]][source]

Return the class path and the keyword arguments to rebuild this (kill_action only if set).

target_states: tuple[str, ...]
yellowdog_provider.triggers.yellowdog_triggers.event_error_message(event: dict[str, Any]) → str[source]

The message of an "error" trigger event, followed by its error_type in parentheses when present.