Skip to content

Hook notification when you turn on/off (pause/unpause) a DAG from the UI #36516

Open

Description

@potiuk

Discussed in #18511

Originally posted by salvob41 September 22, 2021

Description

It would be useful if when someone decide to turn a DAG on/off (pause/unpause) to get notified with a hook/notification that a particular DAG has been turn on (maybe knowing who made this action)

Use case/motivation

it's extremely easy turn a DAG on/off. This might get dangerous when different people (from different team) use airflow as scheduler. Having a hook might give some controls on what is being executed or not.

Related issues

No response

Are you willing to submit a PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Activity

  1. potiuk commented on Dec 31, 2023

    @potiuk
    MemberAuthor

    Just to note - this might be rather complex because it requires a new way of communication. Webserver / API uses DB to communicate with whatever can produce notifications (Webserver shoudl not - on it's own reach out with any kind of custom notifications) - so we need something to be able to react on the fact that DAG has chaned from active to paused. We do not have that something currently.

  2. dirrao commented on Jan 1, 2024

    @dirrao
    Contributor

    Yes, it's a useful feature. A use case could be notify when the production DAGs are turned off/on. So, it will be easy to know and react to them quickly.

    We have multiple sources to change the DAG state. I believe in building the mechanism based on the DB table column change. So that it will work irrespective of the source.

    One possible option could be to publish the DAG state metric. Consumers can monitor the DAG's last state from the metrics and create alerts around it. However, this option doesn't provide a reaction to the state change.

  3. potiuk commented on Jan 1, 2024

    @potiuk
    MemberAuthor

    One possible option could be to publish the DAG state metric. Consumers can monitor the DAG's last state from the metrics and create alerts around it. However, this option doesn't provide a reaction to the state change.

    Correct - my initial proposal in the discussion is active checking via API - metrics is almost the same but we would have to have something gathering and publishing the metrics regularly (still you'd have to monitor the metrics and react). In order to implement this one you'd have to have something regularly checking state of DAGs.

    One of the options would be to build it in DAGFileProcessor. It already parses all dags regularly, so if we store state observed during last parsing, DAGFileProcessor could fire a notification when the state changed from last parsing. A bit racy approach and would have to be carefully done to account for potential state changes while the file is being parsed, but generally doable I think.

  4. Bowrna commented on Jan 2, 2024

    @Bowrna
    Contributor

    @potiuk how about trying this to implement it via listenerplugin?
    I would like to pick up this issue and see if i can work on it.

  5. potiuk commented on Jan 2, 2024

    @potiuk
    MemberAuthor

    Yeah. Sure :). It's a bit more involved though as we need to likstly store "last seen" state of the DAG in the DAG table. But yeeah feel free.

  6. Bowrna commented on Jan 3, 2024

    @Bowrna
    Contributor

    ok @potiuk Let me start it this weekend and come up with initial idea and propose it here for review

  7. Harshith246 commented on Mar 6, 2024

    @Harshith246

    @potiuk ,@Bowrna
    Did you manage to try the above option ?

  8. Bowrna commented on Mar 21, 2024

    @Bowrna
    Contributor

    no i will have more time from this week and let me take a look at this @Harshith246

  9. Bowrna commented on Mar 22, 2024

    @Bowrna
    Contributor

    One possible option could be to publish the DAG state metric. Consumers can monitor the DAG's last state from the metrics and create alerts around it. However, this option doesn't provide a reaction to the state change.

    Correct - my initial proposal in the discussion is active checking via API - metrics is almost the same but we would have to have something gathering and publishing the metrics regularly (still you'd have to monitor the metrics and react). In order to implement this one you'd have to have something regularly checking state of DAGs.

    One of the options would be to build it in DAGFileProcessor. It already parses all dags regularly, so if we store state observed during last parsing, DAGFileProcessor could fire a notification when the state changed from last parsing. A bit racy approach and would have to be carefully done to account for potential state changes while the file is being parsed, but generally doable I think.

    Approach:

    1. Checking in the DAGFileProcessor about the state of the DAG and on noticing change of the state, hook a notification and maintain a state that its notified along with the time at which its notified( or say time at which the state change is seen). - this is active verifying in the DAGFileProcessor side and its like polling technique
    2. ListenerPlugin approach - Watching when the DB gets a state change message and hooking a notification as a result of it. Though this seems like cleaner approach, have to check in depth on which one would be feasible.

    Let me make a elaborate plan and present it with the findings I have collected based on the above 2 approach

  10. XtremAlRaven commented on Jul 24, 2024

    @XtremAlRaven

    Hi! Is this still in progress? We're anxiously awaiting for this feature. I see #38683 is about to be closed in a few days due to becoming stale.

  11. Bowrna commented on Jul 25, 2024

    @Bowrna
    Contributor

    yes, it is still in progress. I have added a few migrations and testing the code changes that I have added.

  12. avanish-garg commented on Sep 1, 2026

    @avanish-garg
    Contributor

    Hi @potiuk — saw this traces back to #18511 where you agreed extending the hook system was the
    better fit than polling. Opened a draft PR with an implementation: #72378.

    Approach: new on_dag_pause_status_change(dag, is_paused) hookspec in
    airflow/listeners/spec/dag.py, mirroring the existing pattern in listeners/spec/dagrun.py.
    Fires from patch_dag() (REST API) and the airflow dags pause/unpause CLI commands when
    is_paused actually changes. Scoped to those two user-initiated paths for now — the scheduler's
    automatic max_consecutive_failed_dag_runs circuit breaker also flips is_paused but does it via
    a bulk UPDATE without loading a DagModel instance, so wiring that one in would need more
    restructuring; happy to add it as a follow-up if useful.

    Opened as a draft to make this concrete rather than just talk about it — not asking for merge yet,
    happy to rework based on feedback.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind:feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions