JH-A-Kim commented on code in PR #70416: URL: https://github.com/apache/airflow/pull/70416#discussion_r3770476101
########## airflow-core/src/airflow/api/common/airflow_health.py: ########## @@ -16,77 +16,165 @@ # under the License. from __future__ import annotations -from typing import Any +from typing import TYPE_CHECKING, Any + +from sqlalchemy import select from airflow.jobs.dag_processor_job_runner import DagProcessorJobRunner +from airflow.jobs.job import Job, JobState from airflow.jobs.scheduler_job_runner import SchedulerJobRunner from airflow.jobs.triggerer_job_runner import TriggererJobRunner +from airflow.utils.session import NEW_SESSION, provide_session + +if TYPE_CHECKING: + from sqlalchemy.orm import Session HEALTHY = "healthy" UNHEALTHY = "unhealthy" +DEGRADED = "degraded" +DOWN = "down" + + +@provide_session +def get_jobs_health(job_runner_class, *, session: Session = NEW_SESSION) -> list[Job]: + """Return all running jobs for the runner class, ordered by latest heartbeat.""" + return list( + session.scalars( + select(Job) + .where( + Job.job_type == job_runner_class.job_type, + Job.state == JobState.RUNNING, Review Comment: Yeah I did notice recently while testing the endpoint that if i ended the service by killing the container, that if i restarted the container and looked at the endpoint their would be previous instances of the components still left over that were not cleaned up because their was nothing to reap them. It would list them as down but running. -- 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]
