Coverage for /usr/local/lib/python3.12/site-packages/prefect/server/api/root.py: 75%
20 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 02:04 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 02:04 +0000
1"""
2Contains the `hello` route for testing and healthcheck purposes.
3"""
5import os
7from fastapi import Depends, status
8from fastapi.responses import JSONResponse
10from prefect.server.database import PrefectDBInterface, provide_database_interface
11from prefect.server.utilities.server import PrefectRouter
12from prefect.settings.context import get_current_settings
14router: PrefectRouter = PrefectRouter(prefix="", tags=["Root"])
17@router.get("/hello")
18async def hello() -> str:
19 """Say hello!"""
20 return "👋"
23@router.get("/ready")
24async def perform_readiness_check(
25 db: PrefectDBInterface = Depends(provide_database_interface),
26) -> JSONResponse:
27 is_db_connectable = await db.is_db_connectable()
29 if is_db_connectable: 29 ↛ 35line 29 didn't jump to line 35 because the condition on line 29 was always true
30 return JSONResponse(
31 status_code=status.HTTP_200_OK,
32 content={"message": "OK"},
33 )
35 return JSONResponse(
36 status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
37 content={"message": "Database is not available"},
38 )
41if get_current_settings().testing.test_mode: 41 ↛ 43line 41 didn't jump to line 43 because the condition on line 41 was never true
43 @router.get("/pid")
44 async def pid() -> JSONResponse:
45 """
46 Returns the process ID of the current process.
48 Used for testing multi-worker server.
49 """
50 return JSONResponse(
51 status_code=status.HTTP_200_OK, content={"pid": os.getpid()}
52 )