first commit
This commit is contained in:
commit
34ea15a54d
246 changed files with 18660 additions and 0 deletions
24
backend/app/api/routes/health.py
Normal file
24
backend/app/api/routes/health.py
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
from fastapi import APIRouter, status
|
||||
from fastapi.responses import JSONResponse
|
||||
|
||||
from app.core.deps import DbSession
|
||||
from app.schemas.health import HealthResponse
|
||||
from app.services.health import check_database
|
||||
|
||||
router = APIRouter(tags=["health"])
|
||||
|
||||
|
||||
@router.get("/health", response_model=HealthResponse)
|
||||
def health_check(db: DbSession) -> HealthResponse | JSONResponse:
|
||||
connected = check_database(db)
|
||||
payload = HealthResponse(
|
||||
status="ok" if connected else "degraded",
|
||||
service="desi-clans-api",
|
||||
database="connected" if connected else "unavailable",
|
||||
)
|
||||
if not connected:
|
||||
return JSONResponse(
|
||||
status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
|
||||
content=payload.model_dump(),
|
||||
)
|
||||
return payload
|
||||
Loading…
Add table
Add a link
Reference in a new issue