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/02 17:14:29 UTC

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

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