Add health and readiness endpoints

This commit is contained in:
Space-Banane
2026-05-20 21:53:12 +02:00
parent 69957f6848
commit 94392c2c99

View File

@@ -28,6 +28,23 @@ app = FastAPI(title="Jellomator")
app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"]) app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"])
@app.get("/healthz")
def healthz():
return {"ok": True}
@app.get("/readyz")
def readyz():
try:
with db() as c:
with c.cursor() as cur:
cur.execute("select 1 as ok")
cur.fetchone()
except Exception:
raise HTTPException(503, "Database not ready")
return {"ok": True}
@contextmanager @contextmanager
def db(): def db():
conn = pymysql.connect( conn = pymysql.connect(