From 7758c8cb8a2287eaf3cee8485c85661cc8931432 Mon Sep 17 00:00:00 2001 From: lexzach Date: Sat, 18 Oct 2025 17:04:01 -0400 Subject: [PATCH] / now checks database before returning 200 --- src/main.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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) }