Add optional DB write probe to readiness endpoint
This commit is contained in:
@@ -51,12 +51,16 @@ def healthz():
|
||||
|
||||
|
||||
@app.get("/readyz")
|
||||
def readyz():
|
||||
def readyz(write_test: bool = False):
|
||||
try:
|
||||
with db() as c:
|
||||
with c.cursor() as cur:
|
||||
cur.execute("select 1 as ok")
|
||||
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:
|
||||
raise HTTPException(503, "Database not ready")
|
||||
return {"ok": True}
|
||||
|
||||
Reference in New Issue
Block a user