feat: add /api/ready readiness probe (DB, data dir, local-first) (#1200)
/api/health is a liveness ping. This adds /api/ready as a readiness /
integrity self-check that returns 503 unless every critical subsystem is
whole, so an orchestrator (Docker/Compose/k8s) can gate traffic on real
readiness rather than mere process liveness:
- database: opens a connection and runs SELECT 1
- data_dir: confirms the data directory exists and is writable
- local_first: reports whether storage stays on the host (informational;
a remote database is a valid deployment, so it never fails readiness)
The check logic lives in src/readiness.py so it is unit-testable in
isolation; the route is a thin wrapper. Covered by tests/test_readiness.py.
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
11
app.py
11
app.py
@@ -772,6 +772,17 @@ async def get_version():
|
||||
async def health_check() -> Dict[str, str]:
|
||||
return {"status": "healthy", "timestamp": datetime.utcnow().isoformat()}
|
||||
|
||||
@app.get("/api/ready")
|
||||
async def readiness_check() -> JSONResponse:
|
||||
"""Readiness / integrity self-check — DB, data dir, local-first storage.
|
||||
|
||||
Unlike /api/health (liveness), this returns 503 unless every critical
|
||||
subsystem is whole, so an orchestrator can gate traffic on real readiness.
|
||||
"""
|
||||
from src.readiness import check_readiness
|
||||
result = check_readiness()
|
||||
return JSONResponse(status_code=200 if result.get("ready") else 503, content=result)
|
||||
|
||||
@app.get("/api/runtime")
|
||||
async def runtime_info() -> Dict[str, object]:
|
||||
in_docker = os.path.exists("/.dockerenv")
|
||||
|
||||
Reference in New Issue
Block a user