diff --git a/src/main.py b/src/main.py index a046746..b6d6897 100644 --- a/src/main.py +++ b/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) }