This commit is contained in:
caramelteawithmint
2026-11-20 11:53:35 +03:00
parent 2b68813b33
commit f856651e57
12 changed files with 409 additions and 153 deletions
+19 -3
View File
@@ -1,25 +1,41 @@
from fastapi import APIRouter, Request
from fastapi.responses import JSONResponse
import socket
from urllib.parse import urlparse
from ..config import get_settings
from ..db import connection
from ..errors import error_response
from ..s3 import get_s3_client
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:
get_s3_client().head_bucket(Bucket=get_settings().s3_bucket)
# 3. Broker (простая проверка TCP-порта)
settings = get_settings()
parsed = urlparse(settings.broker_url)
host = parsed.hostname or "broker"
port = parsed.port or 5672
with socket.create_connection((host, port), timeout=2):
pass
except Exception as e:
print(f"Readiness check failed: {e}")
return error_response(
request, 503, "unavailable", "Зависимость недоступна"
)