Add optional DB write probe to readiness endpoint
This commit is contained in:
@@ -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}
|
||||||
|
|||||||
Reference in New Issue
Block a user