lab4_
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
from fastapi import APIRouter, Request
|
||||
from fastapi.responses import JSONResponse
|
||||
|
||||
from ..db import connection
|
||||
from ..errors import error_response
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/health/live")
|
||||
def live():
|
||||
return {"status": "ok"}
|
||||
|
||||
|
||||
@router.get("/health/ready")
|
||||
def ready(request: Request):
|
||||
try:
|
||||
with connection() as conn:
|
||||
with conn.cursor() as cur:
|
||||
cur.execute("SELECT 1")
|
||||
cur.fetchone()
|
||||
except Exception:
|
||||
return error_response(
|
||||
request, 503, "unavailable", "Зависимость недоступна"
|
||||
)
|
||||
return {"status": "ok"}
|
||||
Reference in New Issue
Block a user