uranusjr commented on code in PR #28119:
URL: https://github.com/apache/airflow/pull/28119#discussion_r1040438334


##########
airflow/jobs/base_job.py:
##########
@@ -125,12 +125,23 @@ def most_recent_job(cls, session=None) -> BaseJob | None:
         Return the most recent job of this type, if any, based on last
         heartbeat received.
 
+        Jobs in "running" state take precedence over others to make sure alive
+        job is returned if it is available.
         This method should be called on a subclass (i.e. on SchedulerJob) to
         return jobs of that type.
 
         :param session: Database session
         """
-        return 
session.query(cls).order_by(cls.latest_heartbeat.desc()).limit(1).first()
+        return (
+            session.query(cls)
+            .order_by(
+                # Make sure "running" jobs first in order.

Review Comment:
   ```suggestion
                   # Put "running" jobs at the front.
   ```



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

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to