ashb commented on code in PR #76751:
URL: https://github.com/apache/airflow/pull/76751#discussion_r4518605329


##########
airflow-core/src/airflow/api/common/airflow_health.py:
##########
@@ -53,16 +55,23 @@ class DetailedHealthStatus(str, Enum):
 
 @provide_session
 def get_jobs_health(job_runner_class, *, session: Session = NEW_SESSION) -> 
list[Job]:
-    """Return unfinished jobs for the runner class, ordered by latest 
heartbeat."""
+    """
+    Return live unfinished jobs and the latest unfinished job, ordered by 
heartbeat.
+
+    Keep the latest job even when dead so health responses retain its 
heartbeat.
+    """
+    job_type = job_runner_class.job_type
+    unfinished = (Job.job_type == job_type, Job.end_date.is_(None))
+    cutoff = timezone.utcnow() - 
timedelta(seconds=health_check_threshold(job_type, 0))
+    latest_job = 
select(Job.id).where(*unfinished).order_by(Job.latest_heartbeat.desc()).limit(1).subquery()
+    live_job_ids = select(Job.id).where(

Review Comment:
   I think three copies is about the point I hit my "DRY it up" limit, so I'd 
say lets fix it in this PR please?



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