Add health and readiness endpoints
This commit is contained in:
@@ -28,6 +28,23 @@ app = FastAPI(title="Jellomator")
|
||||
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
|
||||
def db():
|
||||
conn = pymysql.connect(
|
||||
|
||||
Reference in New Issue
Block a user