File size: 1,305 Bytes
266d7bc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import time

from fastapi import APIRouter, Request
from qdrant_client.http.exceptions import UnexpectedResponse

router = APIRouter()

start_time = time.time()


@router.get("/")
async def root():
    """Root endpoint.

    Returns a simple JSON response indicating that the API is running.

    Returns:
        dict: {"message": "Hello! API is running."}

    """
    return {"message": "Hello! API is running."}


@router.get("/health")
async def health_check():
    """Liveness check endpoint.

    Returns basic service info, uptime, and environment variables.
    """
    uptime = int(time.time() - start_time)
    return {
        "status": "ok",
        "uptime_seconds": uptime,
    }


@router.get("/ready")
async def readiness_check(request: Request):
    """Readiness check endpoint.

    Verifies whether the service is ready to handle requests by
    checking connectivity to Qdrant.
    """
    try:
        vectorstore = request.app.state.vectorstore
        # a lightweight check: list_collections is cheap
        await vectorstore.client.get_collections()
        return {"status": "ready"}
    except UnexpectedResponse:
        return {"status": "not ready", "reason": "Qdrant unexpected response"}
    except Exception as e:
        return {"status": "not ready", "reason": str(e)}