Implement asynchronous database ping for health checks (#24380)

This commit is contained in:
Jacob Leksan
2026-05-08 12:20:11 -04:00
committed by GitHub
parent 1f977d072e
commit 2a18dc98ac

View File

@@ -2812,6 +2812,14 @@ async def get_opensearch_xml():
return Response(content=xml_content, media_type='application/xml')
def _sync_db_ping() -> None:
ScopedSession.execute(text('SELECT 1;')).all()
async def async_db_ping() -> None:
await asyncio.to_thread(_sync_db_ping)
@app.get('/health')
async def healthcheck():
return {'status': True}
@@ -2833,7 +2841,7 @@ async def readiness_check():
# Check database connectivity
try:
ScopedSession.execute(text('SELECT 1;')).all()
await async_db_ping()
except Exception as e:
log.warning(f'Readiness check DB ping failed: {e!r}')
raise HTTPException(
@@ -2860,7 +2868,7 @@ async def readiness_check():
@app.get('/health/db')
async def healthcheck_with_db():
ScopedSession.execute(text('SELECT 1;')).all()
await async_db_ping()
return {'status': True}