Skip to content

Ensure Task Instance Listeners work with Task SDK #45423

Closed

Description

@kaxil

Part of #45491

Port Listeners https://airflow.apache.org/docs/apache-airflow/stable/administration-and-deployment/listeners.html#listeners to Task SDK.

@hookspec
def on_task_instance_running(
previous_state: TaskInstanceState | None, task_instance: TaskInstance, session: Session | None
):
"""Execute when task state changes to RUNNING. previous_state can be None."""
@hookspec
def on_task_instance_success(
previous_state: TaskInstanceState | None, task_instance: TaskInstance, session: Session | None
):
"""Execute when task state changes to SUCCESS. previous_state can be None."""
@hookspec
def on_task_instance_failed(
previous_state: TaskInstanceState | None,
task_instance: TaskInstance,
error: None | str | BaseException,
session: Session | None,
):
"""Execute when task state changes to FAIL. previous_state can be None."""

Activity

  1. added
    area:task-execution-interface-aip72
    on Jan 6, 2025
  2. moved this from Next 2 Weeks to Todo in AIP-72 - Task Execution Interface and SDKon Jan 6, 2025
  3. changed the title [-]Ensure Listeners work with Task SDK[/-] [+]Ensure Task Instance Listeners work with Task SDK[/+] on Jan 8, 2025
  4. added this to the Airflow 3.0.0 milestone on Jan 17, 2025
  5. reopened this on Feb 16, 2025
  6. ashb commented on Feb 16, 2025

    @ashb
    Member

    These aren't fully functional yet -- it doesn't work with errors.

    {"level":"warning","event":"Argument(s) \'error\' which are declared in the hookspec cannot be found in this hook call","category":"UserWarning","filename":"/usr/local/lib/python3.12/site-packages/pluggy/_hooks.py","lineno":510,"logger":"py.warnings"}
    {"level":"debug","event":"Calling \'on_task_instance_failed\' with {\'previous_state\': <TaskInstanceState.RUNNING: \'running\'>, \'task_instance\': RuntimeTaskInstance(id=UUID(\'01950e95-2c03-70c6-a089-308bc7020827\'), task_id=\'waiter\', dag_id=\'trigger_test\', run_id=\'manual__2025-02-16T11:46:52.024510+00:00_RZIbCTvh\', try_number=1, map_index=-1, hostname=\'87ff8343cda4\', task=<Task(TimeDeltaSensorAsync): waiter>, max_tries=0, start_date=datetime.datetime(2025, 2, 16, 11, 46, 52, 637006, tzinfo=TzInfo(UTC)))}","logger":"airflow.listeners.listener"}
    
  7. vatsrahul1001 commented on Mar 11, 2025

    @vatsrahul1001
    Contributor

    @ashb can we close this issue. Airflow 3.0 not emitting OpenLineage Task Failure Events #46915 address this right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:Listenersarea:task-execution-interface-aip72

Type

No type

Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions