/ now checks database before returning 200

This commit is contained in:
2025-10-18 17:04:01 -04:00
parent 7813d9d3fe
commit 7758c8cb8a

View File

@@ -528,6 +528,21 @@ async def get_server_info():
""" """
Return the server name and version 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 = { info = {
"version":"Micro License Server {version}".format(version=VERSION) "version":"Micro License Server {version}".format(version=VERSION)
} }