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_r245173793
##########
File path: airflow/www_rbac/views.py
##########
@@ -147,6 +147,33 @@ def render(self, template, **context):
class Airflow(AirflowBaseView):
+ @expose('/health')
+ @provide_session
+ def health(self, session=None):
+ from sqlalchemy import func
+ 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):
Review comment:
same comment on why we pick 30 seconds as magic number(needs some comments).
And it would be good if we put it in a config value so that it allows users to
change.
----------------------------------------------------------------
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