You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "Bowrna (via GitHub)" <gi...@apache.org> on 2024/04/02 16:50:25 UTC

[PR] adding callback hook for on/off state of dag [airflow]

Bowrna opened a new pull request, #38683:
URL: https://github.com/apache/airflow/pull/38683

   closes: #36516 
   <!--
    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at
   
      http://www.apache.org/licenses/LICENSE-2.0
   
    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.
    -->
   
   <!--
   Thank you for contributing! Please make sure that your code changes
   are covered with tests. And in case of new features or big changes
   remember to adjust the documentation.
   
   Feel free to ping committers for the review!
   
   In case of an existing issue, reference it using one of the following:
   
   closes: #ISSUE
   related: #ISSUE
   
   How to write a good git commit message:
   http://chris.beams.io/posts/git-commit/
   -->
   
   
   
   <!-- Please keep an empty line above the dashes. -->
   ---
   **^ Add meaningful description above**
   Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)** for more information.
   In case of fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed.
   In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   In case of backwards incompatible changes please leave a note in a newsfragment file, named `{pr_number}.significant.rst` or `{issue_number}.significant.rst`, in [newsfragments](https://github.com/apache/airflow/tree/main/newsfragments).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] adding callback hook for on/off state of dag [airflow]

Posted by "Bowrna (via GitHub)" <gi...@apache.org>.
Bowrna commented on code in PR #38683:
URL: https://github.com/apache/airflow/pull/38683#discussion_r1548239659


##########
airflow/models/dag.py:
##########
@@ -690,6 +694,7 @@ def __init__(
                 )
         self.dagrun_timeout = dagrun_timeout
         self.sla_miss_callback = sla_miss_callback
+        self.toggle_dag_callback = toggle_dag_callback

Review Comment:
   @potiuk I have added toggle callback in dag and considering if it could be handled like how manage_slas are handled in processor.py by checking if it violates sla and send callback and additional email notification
   
   Do you think this would be the right direction to proceed?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] adding callback hook for on/off state of dag [airflow]

Posted by "eladkal (via GitHub)" <gi...@apache.org>.
eladkal commented on PR #38683:
URL: https://github.com/apache/airflow/pull/38683#issuecomment-2093495628

   > @eladkal I checked the other issue. It is about adding another mode drain to the paused/unpaused state of DAG. While this PR is to send a callback on this state change. in this PR it monitors the difference of state and invokes the callback if it varies from the previous state of the DAG. Do you think this has to be blocked until the other issue work is done?
   
   Yes. Removed the temporary blocking.
   We can continue with reviewing and merge when ready


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] adding callback hook for on/off state of dag [airflow]

Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on code in PR #38683:
URL: https://github.com/apache/airflow/pull/38683#discussion_r1555005706


##########
airflow/models/dag.py:
##########
@@ -690,6 +694,7 @@ def __init__(
                 )
         self.dagrun_timeout = dagrun_timeout
         self.sla_miss_callback = sla_miss_callback
+        self.toggle_dag_callback = toggle_dag_callback

Review Comment:
   Yes, it could be done this way, though it's a bit complex to implement, just to warn you :)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] adding callback hook for on/off state of dag [airflow]

Posted by "Bowrna (via GitHub)" <gi...@apache.org>.
Bowrna commented on code in PR #38683:
URL: https://github.com/apache/airflow/pull/38683#discussion_r1554794562


##########
airflow/models/dag.py:
##########
@@ -690,6 +694,7 @@ def __init__(
                 )
         self.dagrun_timeout = dagrun_timeout
         self.sla_miss_callback = sla_miss_callback
+        self.toggle_dag_callback = toggle_dag_callback

Review Comment:
   @potiuk can you give me your views when you have time?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] adding callback hook for on/off state of dag [airflow]

Posted by "Bowrna (via GitHub)" <gi...@apache.org>.
Bowrna commented on PR #38683:
URL: https://github.com/apache/airflow/pull/38683#issuecomment-2089667006

   @eladkal I checked the other issue. It is about adding another mode drain to the paused/unpaused state of DAG. While this PR is to send a callback on this state change. in this PR it monitors the difference of state and invokes the callback if it varies from the previous state of the DAG. Do you still think this has to be blocked until the other work is done?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] adding callback hook for on/off state of dag [airflow]

Posted by "Bowrna (via GitHub)" <gi...@apache.org>.
Bowrna commented on PR #38683:
URL: https://github.com/apache/airflow/pull/38683#issuecomment-2088810739

   I have added the changes and included the toggle_dag_callback inside models. But I am not sure how I can test the changes that adds a new table. Can anyone guide me with any sample PR to have a look? ( I tried figuring out but I couldn't find one that would be useful for me)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] adding callback hook for on/off state of dag [airflow]

Posted by "Bowrna (via GitHub)" <gi...@apache.org>.
Bowrna commented on PR #38683:
URL: https://github.com/apache/airflow/pull/38683#issuecomment-2100799176

   > I have added the changes and included the toggle_dag_callback inside models. But I am not sure how I can test the changes that adds a new table. Can anyone guide me with any sample PR to have a look? ( I tried figuring out but I couldn't find one that would be useful for me)
   
   @uranusjr @potiuk Can you give me directions in this part?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] adding callback hook for on/off state of dag [airflow]

Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on PR #38683:
URL: https://github.com/apache/airflow/pull/38683#issuecomment-2102584708

   > @uranusjr @potiuk Can you give me directions in this part?
   
   Look at history of `airflow/migrations` -> this is where migration scripts are maintained and we use alembic to generate / maintain those. Simple description of what needs to be done is in https://github.com/apache/airflow/blob/main/contributing-docs/13_metadata_database_updates.rst - but I personally have never done any of those (somewhat surprisingly) from scratch :)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] adding callback hook for on/off state of dag [airflow]

Posted by "uranusjr (via GitHub)" <gi...@apache.org>.
uranusjr commented on code in PR #38683:
URL: https://github.com/apache/airflow/pull/38683#discussion_r1555446852


##########
airflow/callbacks/callback_requests.py:
##########
@@ -144,3 +144,27 @@ def __init__(
     ):
         super().__init__(full_filepath, processor_subdir=processor_subdir, msg=msg)
         self.dag_id = dag_id
+
+
+class ToggleCallbackRequest(CallbackRequest):
+    """
+    A class with information about the DAG pause/unpause callback to be executed.
+
+    :param full_filepath: File Path to use to run the callback
+    :param dag_id: DAG ID
+    :param processor_subdir: Directory used by Dag Processor when parsed the dag.
+    :param is_toggle_off_callback: Flag to determine whether DAG is paused(off) or unpaused(on) Callback
+    :param msg: Additional Message that can be used for logging
+    """
+
+    def __init__(
+        self,
+        full_filepath: str,
+        dag_id: str,
+        processor_subdir: str | None,
+        is_toggle_off_callback: bool | None = True,

Review Comment:
   I would call this something like `next_state` or `new_state` instead.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org