37494a7192
将 web/routes.py 拆分为模块化 router + service 架构
- 新增 web/app_factory.py 集中注册 7 个域名 router
- 新增 web/routers/ 薄壳路由层(auth/city/system/scan/ops/payments/analytics)
- 新增 web/services/ 业务函数下沉(每域独立 service 文件)
- web/routes.py 缩减为 city_runtime 的兼容重导出 facade
- analysis_service.py/app.py 适配新入口并清理冗余导入
Scope-risk: LOW — 全量 170 测试通过,router 注册顺序与原路由一致
Tested: python -m pytest -q (170 passed), ruff check . (All checks passed)
@
64 lines
1.6 KiB
Python
64 lines
1.6 KiB
Python
"""System and observability API routes for PolyWeather."""
|
|
|
|
from typing import Optional
|
|
|
|
from fastapi import APIRouter, BackgroundTasks, Request
|
|
from fastapi.responses import PlainTextResponse
|
|
|
|
from web.services.system_api import (
|
|
get_health_payload,
|
|
get_prometheus_metrics_response,
|
|
get_system_cache_status,
|
|
get_system_status_payload,
|
|
run_system_prewarm,
|
|
run_system_priority_warm,
|
|
)
|
|
|
|
router = APIRouter(tags=["system"])
|
|
|
|
|
|
@router.get("/healthz")
|
|
async def healthz():
|
|
return get_health_payload()
|
|
|
|
|
|
@router.get("/api/system/status")
|
|
async def system_status():
|
|
return await get_system_status_payload()
|
|
|
|
|
|
@router.post("/api/system/prewarm")
|
|
async def system_prewarm(
|
|
request: Request,
|
|
cities: Optional[str] = None,
|
|
force_refresh: bool = False,
|
|
include_detail: bool = False,
|
|
include_market: bool = False,
|
|
):
|
|
return run_system_prewarm(
|
|
request,
|
|
cities=cities,
|
|
force_refresh=force_refresh,
|
|
include_detail=include_detail,
|
|
include_market=include_market,
|
|
)
|
|
|
|
|
|
@router.get("/api/system/cache-status")
|
|
async def system_cache_status(request: Request, cities: Optional[str] = None):
|
|
return get_system_cache_status(request, cities=cities)
|
|
|
|
|
|
@router.post("/api/system/priority-warm")
|
|
async def system_priority_warm(
|
|
request: Request,
|
|
background_tasks: BackgroundTasks,
|
|
timezone: Optional[str] = None,
|
|
):
|
|
return run_system_priority_warm(request, background_tasks, timezone=timezone)
|
|
|
|
|
|
@router.get("/metrics", response_class=PlainTextResponse)
|
|
async def metrics():
|
|
return get_prometheus_metrics_response()
|