Add optional DB write probe to readiness endpoint

This commit is contained in:
Space-Banane
2026-05-20 21:57:37 +02:00
parent a185c91407
commit 94d12d55c6

View File

@@ -51,12 +51,16 @@ def healthz():
@app.get("/readyz") @app.get("/readyz")
def readyz(): def readyz(write_test: bool = False):
try: try:
with db() as c: with db() as c:
with c.cursor() as cur: with c.cursor() as cur:
cur.execute("select 1 as ok") cur.execute("select 1 as ok")
cur.fetchone() cur.fetchone()
if write_test:
cur.execute("create temporary table if not exists readyz_probe(id int)")
cur.execute("insert into readyz_probe(id) values (1)")
cur.execute("truncate table readyz_probe")
except Exception: except Exception:
raise HTTPException(503, "Database not ready") raise HTTPException(503, "Database not ready")
return {"ok": True} return {"ok": True}