/ now checks database before returning 200
This commit is contained in:
15
src/main.py
15
src/main.py
@@ -528,6 +528,21 @@ async def get_server_info():
|
||||
"""
|
||||
Return the server name and version
|
||||
"""
|
||||
def _check_database():
|
||||
with psycopg.connect(connect_statement) as conn:
|
||||
with conn.cursor() as cur:
|
||||
cur.execute("SELECT 1")
|
||||
cur.fetchone()
|
||||
|
||||
try:
|
||||
await asyncio.to_thread(_check_database)
|
||||
except Exception as exc:
|
||||
logger.exception("Database health check failed.")
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
|
||||
detail="Database unavailable.",
|
||||
) from exc
|
||||
|
||||
info = {
|
||||
"version":"Micro License Server {version}".format(version=VERSION)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user