-
Notifications
You must be signed in to change notification settings - Fork 14.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[AIRFLOW-5269] Reuse session in Scheduler Job from health endpoint #5873
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would remove the decorator from the whole /health
endpoint:
class Airflow(AirflowBaseView):
@expose('/health')
@provide_session
def health(self, session=None):
"""
An endpoint helping check the health status of the Airflow instance,
including metadatabase and scheduler.
"""
payload = {
'metadatabase': {'status': 'unhealthy'}
}
latest_scheduler_heartbeat = None
scheduler_status = 'unhealthy'
payload['metadatabase'] = {'status': 'healthy'}
try:
scheduler_job = jobs.SchedulerJob.most_recent_job(session=session)
if scheduler_job:
latest_scheduler_heartbeat = scheduler_job.latest_heartbeat.isoformat()
if scheduler_job.is_alive():
scheduler_status = 'healthy'
except Exception:
payload['metadatabase']['status'] = 'unhealthy'
payload['scheduler'] = {'status': scheduler_status,
'latest_scheduler_heartbeat': latest_scheduler_heartbeat}
return wwwutils.json_response(payload)
We don't use the session anywhere in the function. This will only keep the session open inside the scope of the most_recent_job()
function. WDYT @kaxil ?
(cherry picked from commit e0c4c6f41b13dd693f249fd8a7d513d8c3515f34)
@Fokko Updated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 👍
…pache#5873) (cherry picked from commit 7debac4)
…pache#5873) (cherry picked from commit 7debac4)
Make sure you have checked all steps below.
Jira
Description
Reuse session in Scheduler Job from health endpoint
Tests
Current tests cover it
Commits
Documentation
Code Quality
flake8