M16: isolate acceptance and harden readiness

This commit is contained in:
NuklearRabbit
2026-08-10 12:08:42 +02:00
parent 2ee8b2d82b
commit 686795a452
13 changed files with 200 additions and 41 deletions
+23
View File
@@ -4,6 +4,7 @@ from contextlib import asynccontextmanager
from fastapi import FastAPI, HTTPException, Request
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import JSONResponse
from sqlalchemy import text
from app.api.routers import (
audit,
@@ -77,6 +78,28 @@ def health() -> dict[str, str]:
return {"status": "ok", "service": "mobilityops-api"}
@app.get("/health/live")
def liveness() -> dict[str, str]:
"""Process liveness only; external dependencies deliberately do not affect it."""
return {"status": "ok", "service": "mobilityops-api"}
@app.get("/health/ready")
def readiness() -> JSONResponse:
"""Traffic readiness: the API is useful only while its canonical database responds."""
try:
with SessionLocal() as db:
db.execute(text("SELECT 1"))
except Exception: # noqa: BLE001 -- readiness must convert infrastructure errors to 503
return JSONResponse(
status_code=503,
content={"status": "not_ready", "service": "mobilityops-api", "database": "down"},
)
return JSONResponse(
content={"status": "ready", "service": "mobilityops-api", "database": "up"}
)
@app.get("/api/v1/system/status")
def system_status() -> dict[str, object]:
return {