potiuk commented on code in PR #23905:
URL: https://github.com/apache/airflow/pull/23905#discussion_r887240643


##########
airflow/utils/scheduler_health.py:
##########
@@ -0,0 +1,32 @@
+from http.server import BaseHTTPRequestHandler
+from http.server import HTTPServer
+from airflow.jobs.scheduler_job import SchedulerJob
+from airflow.utils.db import create_session
+from airflow.utils.net import get_hostname
+from airflow.configuration import conf
+
+
+class HealthServer(BaseHTTPRequestHandler):
+    def do_GET(self):
+        if self.path == '/health':
+            try:
+                with create_session() as session:
+                    scheduler_job = 
session.query(SchedulerJob).filter_by(hostname=get_hostname()).order_by(
+                        SchedulerJob.latest_heartbeat.desc()).limit(1).first()
+                if scheduler_job and scheduler_job.is_alive():
+                    self.send_response(200)
+                    self.end_headers()
+                else:
+                    self.send_error(500)

Review Comment:
   500 should be reserved for "unknown" errors that we could not foresee and 
it's kind of "if all else fails" (not enough memory etc.). I think in this case 
503 would be  better choice here still.



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