airflow.triggers.base

Module Contents

Classes

StartTriggerArgs

Arguments required for start task execution from triggerer.

BaseTrigger

Base class for all triggers.

TriggerEvent

Something that a trigger can fire when its conditions are met.

TaskSuccessEvent

Yield this event in order to end the task successfully.

TaskFailedEvent

Yield this event in order to end the task with failure.

TaskSkippedEvent

Yield this event in order to end the task with status 'skipped'.

Attributes

log

airflow.triggers.base.log[source]
class airflow.triggers.base.StartTriggerArgs[source]

Arguments required for start task execution from triggerer.

trigger_cls: str[source]
next_method: str[source]
trigger_kwargs: dict[str, Any] | None[source]
next_kwargs: dict[str, Any] | None[source]
timeout: datetime.timedelta | None[source]
class airflow.triggers.base.BaseTrigger(**kwargs)[source]

Bases: abc.ABC, airflow.utils.log.logging_mixin.LoggingMixin

Base class for all triggers.

A trigger has two contexts it can exist in:

  • Inside an Operator, when it’s passed to TaskDeferred

  • Actively running in a trigger worker

We use the same class for both situations, and rely on all Trigger classes to be able to return the arguments (possible to encode with Airflow-JSON) that will let them be re-instantiated elsewhere.

abstract serialize()[source]

Return the information needed to reconstruct this Trigger.

Returns

Tuple of (class path, keyword arguments needed to re-instantiate).

Return type

tuple[str, dict[str, Any]]

abstract async run()[source]

Run the trigger in an asynchronous context.

The trigger should yield an Event whenever it wants to fire off an event, and return None if it is finished. Single-event triggers should thus yield and then immediately return.

If it yields, it is likely that it will be resumed very quickly, but it may not be (e.g. if the workload is being moved to another triggerer process, or a multi-event trigger was being used for a single-event task defer).

In either case, Trigger classes should assume they will be persisted, and then rely on cleanup() being called when they are no longer needed.

async cleanup()[source]

Cleanup the trigger.

Called when the trigger is no longer needed, and it’s being removed from the active triggerer process.

This method follows the async/await pattern to allow to run the cleanup in triggerer main event loop. Exceptions raised by the cleanup method are ignored, so if you would like to be able to debug them and be notified that cleanup method failed, you should wrap your code with try/except block and handle it appropriately (in async-compatible way).

static repr(classpath, kwargs)[source]
__repr__()[source]

Return repr(self).

class airflow.triggers.base.TriggerEvent(payload)[source]

Something that a trigger can fire when its conditions are met.

Events must have a uniquely identifying value that would be the same wherever the trigger is run; this is to ensure that if the same trigger is being run in two locations (for HA reasons) that we can deduplicate its events.

__repr__()[source]

Return repr(self).

__eq__(other)[source]

Return self==value.

handle_submit(*, task_instance, session=NEW_SESSION)[source]

Handle the submit event for a given task instance.

This function sets the next method and next kwargs of the task instance, as well as its state to scheduled. It also adds the event’s payload into the kwargs for the task.

Parameters
  • task_instance (airflow.models.TaskInstance) – The task instance to handle the submit event for.

  • session (sqlalchemy.orm.Session) – The session to be used for the database callback sink.

class airflow.triggers.base.TaskSuccessEvent(*, xcoms=None, **kwargs)[source]

Bases: BaseTaskEndEvent

Yield this event in order to end the task successfully.

task_instance_state[source]
class airflow.triggers.base.TaskFailedEvent(*, xcoms=None, **kwargs)[source]

Bases: BaseTaskEndEvent

Yield this event in order to end the task with failure.

task_instance_state[source]
class airflow.triggers.base.TaskSkippedEvent(*, xcoms=None, **kwargs)[source]

Bases: BaseTaskEndEvent

Yield this event in order to end the task with status ‘skipped’.

task_instance_state[source]

Was this entry helpful?