|
14 | 14 | from contextlib import asynccontextmanager |
15 | 15 | from typing import TYPE_CHECKING, Any |
16 | 16 |
|
| 17 | +import httpx |
17 | 18 | from fastapi import FastAPI |
18 | 19 |
|
19 | 20 | from app.api.routes import router |
@@ -42,6 +43,27 @@ async def _default_lifespan(app: FastAPI) -> AsyncGenerator[None]: |
42 | 43 | # Configure logging |
43 | 44 | logging.basicConfig(level=getattr(logging, settings.log_level.upper(), logging.INFO)) |
44 | 45 |
|
| 46 | + # Verify Lychee connectivity |
| 47 | + lychee_up_url = f"{settings.lychee_api_url}/up" |
| 48 | + logger.info("Checking Lychee connectivity at %s", lychee_up_url) |
| 49 | + try: |
| 50 | + async with httpx.AsyncClient(verify=settings.verify_ssl, timeout=10.0) as client: |
| 51 | + response = await client.get(lychee_up_url) |
| 52 | + response.raise_for_status() |
| 53 | + logger.info("✓ Lychee is reachable (status=%d)", response.status_code) |
| 54 | + except httpx.HTTPStatusError as e: |
| 55 | + logger.error("✗ Lychee /up endpoint returned status %d", e.response.status_code) |
| 56 | + raise RuntimeError( |
| 57 | + f"Lychee health check failed: /up returned {e.response.status_code}. " |
| 58 | + "Ensure VISION_FACE_LYCHEE_API_URL is correct and Lychee is running." |
| 59 | + ) from e |
| 60 | + except httpx.RequestError as e: |
| 61 | + logger.error("✗ Cannot connect to Lychee at %s: %s", lychee_up_url, e) |
| 62 | + raise RuntimeError( |
| 63 | + f"Cannot connect to Lychee at {lychee_up_url}. " |
| 64 | + "Ensure VISION_FACE_LYCHEE_API_URL is correct and Lychee is reachable." |
| 65 | + ) from e |
| 66 | + |
45 | 67 | # Load detector |
46 | 68 | from app.detection.detector import FaceDetector |
47 | 69 |
|
|
0 commit comments