adityav commented on a change in pull request #6340: [Airflow-5660] Try to find 
the task in DB before regressing to search…
URL: https://github.com/apache/airflow/pull/6340#discussion_r335107805
 
 

 ##########
 File path: airflow/executors/kubernetes_executor.py
 ##########
 @@ -545,6 +545,26 @@ def _labels_to_key(self, labels):
             return None
 
         with create_session() as session:
+            # check if we can find the task directly before scanning
+            # every task with the execution_date
+            task = (
+                session
+                .query(TaskInstance)
+                .filter_by(task_id=task_id, dag_id=dag_id, 
execution_date=ex_time)
+                .first()
+            )
+            if task:
+                self.log.info(
+                    'Found matching task %s-%s (%s) with current state of %s',
+                    task.dag_id, task.task_id, task.execution_date, task.state
+                )
+                return (dag_id, task_id, ex_time, try_num)
+            else:
+                self.log.warning(
+                    "Unable to find Task in db directly for %s-%s (%s). Scan 
all tasks",
 
 Review comment:
   sure. I will rework the code a bit to check for this explicitly.

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to