mirror of
https://github.com/open-webui/open-webui.git
synced 2026-07-10 20:40:18 +02:00
Implement asynchronous database ping for health checks (#24380)
This commit is contained in:
@@ -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}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user