You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
816 B
Python
30 lines
816 B
Python
from __future__ import annotations
|
|
|
|
from fastapi import APIRouter, Depends, Request, status
|
|
from fastapi.responses import JSONResponse
|
|
from sqlalchemy.orm import Session
|
|
|
|
from iti.db import get_db
|
|
from iti.db.session import ping_database
|
|
|
|
router = APIRouter(tags=["health"])
|
|
|
|
|
|
@router.get("/health", include_in_schema=False)
|
|
def health() -> dict[str, str]:
|
|
return {"status": "ok"}
|
|
|
|
|
|
@router.get("/ready", include_in_schema=False)
|
|
def ready(request: Request, db: Session = Depends(get_db)):
|
|
config = request.app.state.config
|
|
if config.ready_check_db:
|
|
try:
|
|
ping_database(db)
|
|
except Exception:
|
|
return JSONResponse(
|
|
status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
|
|
content={"status": "error"},
|
|
)
|
|
return {"status": "ok"}
|