airflow.example_dags.plugins.event_listener

Functions

on_task_instance_running(previous_state, task_instance)

Called when task state changes to RUNNING.

on_task_instance_success(previous_state, task_instance)

Called when task state changes to SUCCESS.

on_task_instance_failed(previous_state, task_instance, ...)

Called when task state changes to FAILED.

on_task_instance_skipped(previous_state, task_instance)

Called when a task instance skips itself during execution.

on_dag_run_success(dag_run, msg)

This method is called when dag run state changes to SUCCESS.

on_dag_run_failed(dag_run, msg)

This method is called when dag run state changes to FAILED.

on_dag_run_running(dag_run, msg)

This method is called when dag run state changes to RUNNING.

Module Contents

airflow.example_dags.plugins.event_listener.on_task_instance_running(previous_state, task_instance)[source]

Called when task state changes to RUNNING.

previous_task_state and task_instance object can be used to retrieve more information about current task_instance that is running, its dag_run, task and dag information.

airflow.example_dags.plugins.event_listener.on_task_instance_success(previous_state, task_instance)[source]

Called when task state changes to SUCCESS.

previous_task_state and task_instance object can be used to retrieve more information about current task_instance that has succeeded, its dag_run, task and dag information.

A RuntimeTaskInstance is provided in most cases, except when the task’s state change is triggered through the API. In that case, the TaskInstance available on the API server will be provided instead.

airflow.example_dags.plugins.event_listener.on_task_instance_failed(previous_state, task_instance, error)[source]

Called when task state changes to FAILED.

previous_task_state, task_instance object and error can be used to retrieve more information about current task_instance that has failed, its dag_run, task and dag information.

A RuntimeTaskInstance is provided in most cases, except when the task’s state change is triggered through the API. In that case, the TaskInstance available on the API server will be provided instead.

airflow.example_dags.plugins.event_listener.on_task_instance_skipped(previous_state, task_instance)[source]

Called when a task instance skips itself during execution.

This hook is called only when a task has started execution and then intentionally skips itself (e.g., by raising AirflowSkipException).

Note: This function will NOT cover tasks that were skipped by scheduler, before execution began, such as:
  • Skips due to trigger rules (e.g., upstream failures)

  • Skips from operators like BranchPythonOperator, ShortCircuitOperator, or similar mechanisms

  • Any other situation in which the scheduler decides not to schedule a task for execution

For comprehensive tracking of skipped tasks, use DAG-level listeners (on_dag_run_success/on_dag_run_failed) which may have access to all task states.

airflow.example_dags.plugins.event_listener.on_dag_run_success(dag_run, msg)[source]

This method is called when dag run state changes to SUCCESS.

airflow.example_dags.plugins.event_listener.on_dag_run_failed(dag_run, msg)[source]

This method is called when dag run state changes to FAILED.

airflow.example_dags.plugins.event_listener.on_dag_run_running(dag_run, msg)[source]

This method is called when dag run state changes to RUNNING.

Was this entry helpful?