feng-tao commented on a change in pull request #4309: [AIRFLOW-3504] 
Extend/refine the functionality of "/health" endpoint
URL: https://github.com/apache/incubator-airflow/pull/4309#discussion_r245173229
 
 

 ##########
 File path: airflow/www/blueprints.py
 ##########
 @@ -32,6 +37,26 @@ def index():
 
 @routes.route('/health')
 def health():
-    """ We can add an array of tests here to check the server's health """
-    content = Markup(markdown.markdown("The server is healthy!"))
-    return content
+    session = settings.Session()
+    DM = models.DagModel
+    payload = {}
+
+    latest_scheduler_run = None
+    payload['metadatabase'] = {'status': 'healthy'}
+    try:
+        latest_scheduler_run = 
session.query(func.max(DM.last_scheduler_run)).scalar()
+    except Exception as _:
+        payload['metadatabase']['status'] = 'unhealthy'
+
+    if not latest_scheduler_run:
+        scheduler_status = 'unhealthy'
+    else:
+        if timezone.utcnow() - latest_scheduler_run <= timedelta(seconds=30):
+            scheduler_status = 'healthy'
+        else:
+            scheduler_status = 'unhealthy'
+
+    payload['scheduler'] = {'status': scheduler_status,
+                            'latest_scheduler_run': str(latest_scheduler_run)}
 
 Review comment:
   what is the reason behind converting the datetime object to a string type?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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