You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2020/06/01 07:39:03 UTC

[GitHub] [airflow] turbaszek opened a new pull request #9087: Query TaskReschedule only if task is UP_FOR_RESCHEDULE

turbaszek opened a new pull request #9087:
URL: https://github.com/apache/airflow/pull/9087


   ---
   Make sure to mark the boxes below before creating PR: [x]
   
   - [x] Description above provides context of the change
   - [x] Unit tests coverage for changes (not needed for documentation changes)
   - [x] Target Github ISSUE in description if exists
   - [x] Commits follow "[How to write a good git commit message](http://chris.beams.io/posts/git-commit/)"
   - [x] Relevant documentation is updated including usage instructions.
   - [x] I will engage committers as explained in [Contribution Workflow Example](https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst#contribution-workflow-example).
   
   ---
   In case of fundamental code change, Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvements+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 [UPDATING.md](https://github.com/apache/airflow/blob/master/UPDATING.md).
   Read the [Pull Request Guidelines](https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst#pull-request-guidelines) for more information.
   


----------------------------------------------------------------
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.

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



[GitHub] [airflow] ashb commented on a change in pull request #9087: Query TaskReschedule only if task is UP_FOR_RESCHEDULE

Posted by GitBox <gi...@apache.org>.
ashb commented on a change in pull request #9087:
URL: https://github.com/apache/airflow/pull/9087#discussion_r435213323



##########
File path: airflow/ti_deps/deps/ready_to_reschedule.py
##########
@@ -52,14 +52,14 @@ def _get_dep_statuses(self, ti, session, dep_context):
                 reason="The task instance is not in State_UP_FOR_RESCHEDULE or NONE state.")
             return
 
-        task_reschedules = TaskReschedule.find_for_task_instance(task_instance=ti)
-        if not task_reschedules:
+        task_reschedule = TaskReschedule.query_for_task_instance(task_instance=ti, descending=True).first()

Review comment:
       Please pass on the same session object.
   ```suggestion
           task_reschedule = (
               TaskReschedule.query_for_task_instance(task_instance=ti, descending=True, session=session)
               .with_entities(TR.reschedule_date)
               .first()
           )
   ```




----------------------------------------------------------------
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.

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



[GitHub] [airflow] turbaszek commented on pull request #9087: Query TaskReschedule only if task is UP_FOR_RESCHEDULE

Posted by GitBox <gi...@apache.org>.
turbaszek commented on pull request #9087:
URL: https://github.com/apache/airflow/pull/9087#issuecomment-637350057


   > Another optimization could be to not fetch all `TaskReschedule` objects but only the first one. Similar in `ready_to_reschedule.py` only the last one is needed. 
   
   Sounds reasonable, thanks!
   


----------------------------------------------------------------
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.

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



[GitHub] [airflow] turbaszek removed a comment on pull request #9087: Query TaskReschedule only if task is UP_FOR_RESCHEDULE

Posted by GitBox <gi...@apache.org>.
turbaszek removed a comment on pull request #9087:
URL: https://github.com/apache/airflow/pull/9087#issuecomment-638164581


   CI error: `AssertionError: The expected number of db queries is 131. The current number is 135.`


----------------------------------------------------------------
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.

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



[GitHub] [airflow] seelmann commented on pull request #9087: Query TaskReschedule only if task is UP_FOR_RESCHEDULE

Posted by GitBox <gi...@apache.org>.
seelmann commented on pull request #9087:
URL: https://github.com/apache/airflow/pull/9087#issuecomment-636907078


   Makes perfect sense, +1.
   
   Another optimization could be to not fetch all `TaskReschedule` objects but only the first one. Similar in `ready_to_reschedule.py` only the last one is needed. I wanted to change that long time ago but didn't fine the time and then forgot...
   


----------------------------------------------------------------
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.

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



[GitHub] [airflow] mik-laj commented on pull request #9087: Query TaskReschedule only if task is UP_FOR_RESCHEDULE

Posted by GitBox <gi...@apache.org>.
mik-laj commented on pull request #9087:
URL: https://github.com/apache/airflow/pull/9087#issuecomment-640183967


   @turbaszek Should we merge it?


----------------------------------------------------------------
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.

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



[GitHub] [airflow] turbaszek commented on pull request #9087: Query TaskReschedule only if task is UP_FOR_RESCHEDULE

Posted by GitBox <gi...@apache.org>.
turbaszek commented on pull request #9087:
URL: https://github.com/apache/airflow/pull/9087#issuecomment-638836401


   @ashb @mik-laj your suggestions are added 


----------------------------------------------------------------
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.

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



[GitHub] [airflow] seelmann edited a comment on pull request #9087: Query TaskReschedule only if task is UP_FOR_RESCHEDULE

Posted by GitBox <gi...@apache.org>.
seelmann edited a comment on pull request #9087:
URL: https://github.com/apache/airflow/pull/9087#issuecomment-636907078


   Makes perfect sense, +1.
   
   Another optimization could be to not fetch all `TaskReschedule` objects but only the first one. Similar in `ready_to_reschedule.py` only the last one is needed. I wanted to change that long time ago but didn't find the time and then forgot...
   


----------------------------------------------------------------
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.

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



[GitHub] [airflow] mik-laj commented on a change in pull request #9087: Query TaskReschedule only if task is UP_FOR_RESCHEDULE

Posted by GitBox <gi...@apache.org>.
mik-laj commented on a change in pull request #9087:
URL: https://github.com/apache/airflow/pull/9087#discussion_r435123959



##########
File path: airflow/ti_deps/deps/ready_to_reschedule.py
##########
@@ -52,14 +52,14 @@ def _get_dep_statuses(self, ti, session, dep_context):
                 reason="The task instance is not in State_UP_FOR_RESCHEDULE or NONE state.")
             return
 
-        task_reschedules = TaskReschedule.find_for_task_instance(task_instance=ti)
-        if not task_reschedules:
+        task_reschedule = TaskReschedule.query_for_task_instance(task_instance=ti, descending=True).first()

Review comment:
       ```suggestion
           task_reschedule = (
               TaskReschedule.query_for_task_instance(task_instance=ti, descending=True)
               .with_entities(TR.reschedule_date)
               .first()
           )
   ```




----------------------------------------------------------------
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.

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



[GitHub] [airflow] turbaszek merged pull request #9087: Query TaskReschedule only if task is UP_FOR_RESCHEDULE

Posted by GitBox <gi...@apache.org>.
turbaszek merged pull request #9087:
URL: https://github.com/apache/airflow/pull/9087


   


----------------------------------------------------------------
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.

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



[GitHub] [airflow] mik-laj commented on a change in pull request #9087: Query TaskReschedule only if task is UP_FOR_RESCHEDULE

Posted by GitBox <gi...@apache.org>.
mik-laj commented on a change in pull request #9087:
URL: https://github.com/apache/airflow/pull/9087#discussion_r435199093



##########
File path: airflow/ti_deps/deps/ready_to_reschedule.py
##########
@@ -52,14 +52,14 @@ def _get_dep_statuses(self, ti, session, dep_context):
                 reason="The task instance is not in State_UP_FOR_RESCHEDULE or NONE state.")
             return
 
-        task_reschedules = TaskReschedule.find_for_task_instance(task_instance=ti)
-        if not task_reschedules:
+        task_reschedule = TaskReschedule.query_for_task_instance(task_instance=ti, descending=True).first()

Review comment:
       Here is doc: https://docs.sqlalchemy.org/en/13/orm/query.html#sqlalchemy.orm.query.Query.with_entities




----------------------------------------------------------------
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.

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



[GitHub] [airflow] turbaszek commented on pull request #9087: Query TaskReschedule only if task is UP_FOR_RESCHEDULE

Posted by GitBox <gi...@apache.org>.
turbaszek commented on pull request #9087:
URL: https://github.com/apache/airflow/pull/9087#issuecomment-638164581


   CI error: `AssertionError: The expected number of db queries is 131. The current number is 135.`


----------------------------------------------------------------
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.

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



[GitHub] [airflow] mik-laj commented on pull request #9087: Query TaskReschedule only if task is UP_FOR_RESCHEDULE

Posted by GitBox <gi...@apache.org>.
mik-laj commented on pull request #9087:
URL: https://github.com/apache/airflow/pull/9087#issuecomment-636750460


   @seelmann Can you look at it?


----------------------------------------------------------------
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.

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



[GitHub] [airflow] seelmann commented on a change in pull request #9087: Query TaskReschedule only if task is UP_FOR_RESCHEDULE

Posted by GitBox <gi...@apache.org>.
seelmann commented on a change in pull request #9087:
URL: https://github.com/apache/airflow/pull/9087#discussion_r434039646



##########
File path: airflow/models/taskreschedule.py
##########
@@ -63,24 +63,41 @@ def __init__(self, task, execution_date, try_number, start_date, end_date,
 
     @staticmethod
     @provide_session
-    def find_for_task_instance(task_instance, session=None):
+    def query_for_task_instance(task_instance, descending=False, session=None):
         """
-        Returns all task reschedules for the task instance and try number,
-        in ascending order.
+        Returns query for task reschedules for a given the task instance.
 
         :param session: the database session object
         :type session: sqlalchemy.orm.session.Session
         :param task_instance: the task instance to find task reschedules for
         :type task_instance: airflow.models.TaskInstance
+        :param descending: If True then records are returned in descending order
+        :type descending: bool
         """
         TR = TaskReschedule
-        return (
+        qry = (
             session
             .query(TR)
             .filter(TR.dag_id == task_instance.dag_id,
                     TR.task_id == task_instance.task_id,
                     TR.execution_date == task_instance.execution_date,
                     TR.try_number == task_instance.try_number)
-            .order_by(asc(TR.id))
-            .all()
         )
+        if descending:
+            return qry.order_by(desc(TaskReschedule.id))

Review comment:
       ```suggestion
               return qry.order_by(desc(TR.id))
   ```

##########
File path: airflow/models/taskreschedule.py
##########
@@ -63,24 +63,41 @@ def __init__(self, task, execution_date, try_number, start_date, end_date,
 
     @staticmethod
     @provide_session
-    def find_for_task_instance(task_instance, session=None):
+    def query_for_task_instance(task_instance, descending=False, session=None):
         """
-        Returns all task reschedules for the task instance and try number,
-        in ascending order.
+        Returns query for task reschedules for a given the task instance.
 
         :param session: the database session object
         :type session: sqlalchemy.orm.session.Session
         :param task_instance: the task instance to find task reschedules for
         :type task_instance: airflow.models.TaskInstance
+        :param descending: If True then records are returned in descending order
+        :type descending: bool
         """
         TR = TaskReschedule
-        return (
+        qry = (
             session
             .query(TR)
             .filter(TR.dag_id == task_instance.dag_id,
                     TR.task_id == task_instance.task_id,
                     TR.execution_date == task_instance.execution_date,
                     TR.try_number == task_instance.try_number)
-            .order_by(asc(TR.id))
-            .all()
         )
+        if descending:
+            return qry.order_by(desc(TaskReschedule.id))
+        else:
+            return qry.order_by(asc(TaskReschedule.id))

Review comment:
       ```suggestion
               return qry.order_by(asc(TR.id))
   ```




----------------------------------------------------------------
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.

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



[GitHub] [airflow] mik-laj commented on a change in pull request #9087: Query TaskReschedule only if task is UP_FOR_RESCHEDULE

Posted by GitBox <gi...@apache.org>.
mik-laj commented on a change in pull request #9087:
URL: https://github.com/apache/airflow/pull/9087#discussion_r435197947



##########
File path: airflow/ti_deps/deps/ready_to_reschedule.py
##########
@@ -52,14 +52,14 @@ def _get_dep_statuses(self, ti, session, dep_context):
                 reason="The task instance is not in State_UP_FOR_RESCHEDULE or NONE state.")
             return
 
-        task_reschedules = TaskReschedule.find_for_task_instance(task_instance=ti)
-        if not task_reschedules:
+        task_reschedule = TaskReschedule.query_for_task_instance(task_instance=ti, descending=True).first()

Review comment:
       This allows you to change the content of the parameter passed to the query method on an existing object. We already use it in the project. https://github.com/apache/airflow/pull/8729/files




----------------------------------------------------------------
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.

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



[GitHub] [airflow] ashb commented on a change in pull request #9087: Query TaskReschedule only if task is UP_FOR_RESCHEDULE

Posted by GitBox <gi...@apache.org>.
ashb commented on a change in pull request #9087:
URL: https://github.com/apache/airflow/pull/9087#discussion_r435195870



##########
File path: airflow/ti_deps/deps/ready_to_reschedule.py
##########
@@ -52,14 +52,14 @@ def _get_dep_statuses(self, ti, session, dep_context):
                 reason="The task instance is not in State_UP_FOR_RESCHEDULE or NONE state.")
             return
 
-        task_reschedules = TaskReschedule.find_for_task_instance(task_instance=ti)
-        if not task_reschedules:
+        task_reschedule = TaskReschedule.query_for_task_instance(task_instance=ti, descending=True).first()

Review comment:
       Oh does `with_entites` say "just select this one column? Nice!




----------------------------------------------------------------
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.

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



[GitHub] [airflow] ashb commented on a change in pull request #9087: Query TaskReschedule only if task is UP_FOR_RESCHEDULE

Posted by GitBox <gi...@apache.org>.
ashb commented on a change in pull request #9087:
URL: https://github.com/apache/airflow/pull/9087#discussion_r435284611



##########
File path: airflow/ti_deps/deps/ready_to_reschedule.py
##########
@@ -52,14 +52,14 @@ def _get_dep_statuses(self, ti, session, dep_context):
                 reason="The task instance is not in State_UP_FOR_RESCHEDULE or NONE state.")
             return
 
-        task_reschedules = TaskReschedule.find_for_task_instance(task_instance=ti)
-        if not task_reschedules:
+        task_reschedule = TaskReschedule.query_for_task_instance(task_instance=ti, descending=True).first()

Review comment:
       You missed Kamil's suggestion of `.with_entites` here.




----------------------------------------------------------------
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.

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



[GitHub] [airflow] turbaszek commented on a change in pull request #9087: Query TaskReschedule only if task is UP_FOR_RESCHEDULE

Posted by GitBox <gi...@apache.org>.
turbaszek commented on a change in pull request #9087:
URL: https://github.com/apache/airflow/pull/9087#discussion_r435294802



##########
File path: airflow/ti_deps/deps/ready_to_reschedule.py
##########
@@ -52,14 +52,14 @@ def _get_dep_statuses(self, ti, session, dep_context):
                 reason="The task instance is not in State_UP_FOR_RESCHEDULE or NONE state.")
             return
 
-        task_reschedules = TaskReschedule.find_for_task_instance(task_instance=ti)
-        if not task_reschedules:
+        task_reschedule = TaskReschedule.query_for_task_instance(task_instance=ti, descending=True).first()

Review comment:
       I think it's there :)




----------------------------------------------------------------
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.

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



[GitHub] [airflow] turbaszek commented on pull request #9087: Query TaskReschedule only if task is UP_FOR_RESCHEDULE

Posted by GitBox <gi...@apache.org>.
turbaszek commented on pull request #9087:
URL: https://github.com/apache/airflow/pull/9087#issuecomment-637557230


   @seelmann would like to take another look?


----------------------------------------------------------------
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.

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