Files
POPS/app/main.py
Martin Hohenberg 03eebc4f9b Expose DB connection error in /health response for debugging
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-18 21:10:38 +02:00

37 lines
687 B
Python

import logging
from contextlib import asynccontextmanager
from fastapi import FastAPI
from app.db import check_db
logger = logging.getLogger("pops")
@asynccontextmanager
async def lifespan(app: FastAPI):
ok, msg = check_db()
if ok:
logger.info("Database connection OK")
else:
logger.warning("Database unreachable: %s", msg)
yield
app = FastAPI(title="POPS", lifespan=lifespan)
@app.get("/")
def root():
return {"message": "Hello from POPS"}
@app.get("/health")
def health():
ok, msg = check_db()
return {
"status": "ok" if ok else "degraded",
"db": "connected" if ok else "unreachable",
"detail": msg,
}