- Added `list_nav_history` method in `CoreReadOnlyRepository` to retrieve historical NAV data for products over a specified number of days. - Introduced `get_nav_history` endpoint in `product_service` to return historical NAV sequences, improving product data accessibility. - Updated `products.py` to include new API endpoint for fetching NAV history, ensuring compliance with access control. - Enhanced `ready.py` to include a health check for the new functionality, ensuring system readiness. - Updated documentation to reflect the new testing baseline of 833 passed tests, indicating improved stability and functionality across the application. This update significantly enhances the product API by providing access to historical NAV data, improving user insights into product performance.
46 lines
1.4 KiB
Python
46 lines
1.4 KiB
Python
"""启动自检:Redis + 关键路由是否挂载(前端 Topbar 条用)。"""
|
|
from __future__ import annotations
|
|
|
|
from fastapi import APIRouter, FastAPI, Request
|
|
|
|
from app.config.settings import settings
|
|
|
|
router = APIRouter(tags=["platform"])
|
|
|
|
|
|
def build_ready_payload(app: FastAPI, trace_id: str) -> dict:
|
|
checks: dict[str, bool | str] = {}
|
|
|
|
try:
|
|
from app.service.risk import redis_gateway
|
|
|
|
gw = redis_gateway.get_gateway()
|
|
gw.ping()
|
|
checks["redis"] = True
|
|
except Exception as exc: # noqa: BLE001
|
|
checks["redis"] = False
|
|
checks["redis_error"] = str(exc)[:120]
|
|
|
|
paths = set(app.openapi().get("paths", {}).keys())
|
|
checks["chat_close_all"] = "/api/chat/sessions/close-all" in paths
|
|
checks["chat_sessions"] = "/api/chat/sessions" in paths
|
|
checks["analyst_chat"] = "/api/analyst/chat" in paths
|
|
|
|
critical = [checks["chat_close_all"], checks["chat_sessions"], checks["analyst_chat"]]
|
|
routes_ok = all(critical)
|
|
redis_ok = checks.get("redis") is True
|
|
ok = routes_ok
|
|
return {
|
|
"ok": ok,
|
|
"degraded": routes_ok and not redis_ok,
|
|
"env": settings.app_env,
|
|
"trace_id": trace_id,
|
|
"checks": checks,
|
|
}
|
|
|
|
|
|
@router.get("/api/ready")
|
|
def ready(request: Request):
|
|
trace_id = getattr(request.state, "trace_id", "unknown")
|
|
return build_ready_payload(request.app, trace_id)
|