完全移除预热(prewarm)功能

- 删除 src/utils/prewarm_dashboard.py
- 删除 scripts/prewarm_dashboard_cache.py、prewarm_dashboard_worker.py
- docker-compose.yml 移除 polyweather_prewarm 服务
- runtime_coordinator.py 移除预热循环启动逻辑
- web/core.py 移除 prewarm status 上报
- web/routers/system.py 移除 /api/system/prewarm 端点
- web/services/system_api.py 移除 run_system_prewarm
- city_runtime.py DEFAULT_PREWARM_CITIES 改名为 DEFAULT_STATUS_CITIES
- 清理 env.example、测试、VPS .env 中的预热配置
This commit is contained in:
2569718930@qq.com
2026-05-17 22:43:17 +08:00
parent 22e2409e13
commit bd21b05fbc
12 changed files with 4 additions and 713 deletions
-2
View File
@@ -21,7 +21,6 @@ from src.data_collection.country_networks import provider_coverage_summary
from src.data_collection.city_risk_profiles import CITY_RISK_PROFILES # noqa: F401
from src.data_collection.polymarket_readonly import PolymarketReadOnlyLayer
from src.auth.supabase_entitlement import SUPABASE_ENTITLEMENT, extract_bearer_token
from src.utils.prewarm_dashboard import get_prewarm_runtime_summary
from src.utils.metrics import (
build_metrics_summary,
counter_inc,
@@ -836,6 +835,5 @@ def build_system_status_payload() -> Dict[str, Any]:
"probability": _probability_summary(),
"training_data": _training_data_summary(),
"station_networks": provider_coverage_summary(),
"prewarm": get_prewarm_runtime_summary(),
"cities_count": len(CITIES),
}
-18
View File
@@ -11,7 +11,6 @@ from web.services.system_api import (
get_prometheus_metrics_response,
get_system_cache_status,
get_system_status_payload,
run_system_prewarm,
run_system_priority_warm,
)
@@ -28,23 +27,6 @@ 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)
+2 -2
View File
@@ -80,7 +80,7 @@ TRACKABLE_ANALYTICS_EVENTS = {
"checkout_succeeded",
}
DEFAULT_PREWARM_CITIES = [
DEFAULT_STATUS_CITIES = [
"ankara",
"istanbul",
"shanghai",
@@ -658,7 +658,7 @@ def _normalize_city_or_404(name: str) -> str:
def _normalize_city_list(raw: Optional[str]) -> list[str]:
if not raw:
return list(DEFAULT_PREWARM_CITIES)
return list(DEFAULT_STATUS_CITIES)
out: list[str] = []
for part in str(raw).split(","):
city = str(part or "").strip().lower().replace("-", " ")
+1 -1
View File
@@ -23,7 +23,7 @@ def _resolve_default_city(request: Request) -> Optional[str]:
cities_map = getattr(legacy_routes, "TIMEZONE_DEFAULT_CITIES", {})
if tz in cities_map:
return cities_map[tz]
return next(iter(getattr(legacy_routes, "DEFAULT_PREWARM_CITIES", [])), None)
return next(iter(getattr(legacy_routes, "DEFAULT_STATUS_CITIES", [])), None)
async def build_dashboard_init_payload(request: Request) -> Dict[str, Any]:
+1 -71
View File
@@ -26,81 +26,11 @@ async def get_system_status_payload() -> Dict[str, Any]:
return await run_in_threadpool(build_system_status_payload)
def run_system_prewarm(
request: Request,
*,
cities: Optional[str] = None,
force_refresh: bool = False,
include_detail: bool = False,
include_market: bool = False,
) -> Dict[str, Any]:
legacy_routes._assert_entitlement(request)
selected = legacy_routes._normalize_city_list(cities)
if not selected:
raise HTTPException(status_code=400, detail="No valid cities to prewarm")
started = time.perf_counter()
warmed: list[dict[str, object]] = []
failed: list[dict[str, object]] = []
summary_ok = 0
detail_ok = 0
market_ok = 0
for city in selected:
city_started = time.perf_counter()
try:
legacy_routes._refresh_city_summary_cache(city, force_refresh=force_refresh)
entry: dict[str, object] = {
"city": city,
"summary": True,
"duration_ms": round((time.perf_counter() - city_started) * 1000.0, 1),
}
summary_ok += 1
if include_detail:
legacy_routes._refresh_city_panel_cache(city, force_refresh=force_refresh)
entry["detail"] = True
detail_ok += 1
if include_market:
entry["market"] = False
warmed.append(entry)
except Exception as exc:
failed.append(
{
"city": city,
"error": str(exc),
"duration_ms": round((time.perf_counter() - city_started) * 1000.0, 1),
}
)
total_ms = round((time.perf_counter() - started) * 1000.0, 1)
logger.info(
"system prewarm finished count={} failed={} force_refresh={} include_detail={} include_market={} duration_ms={}",
len(warmed),
len(failed),
force_refresh,
include_detail,
include_market,
total_ms,
)
return {
"ok": len(failed) == 0,
"cities": selected,
"warmed": warmed,
"failed": failed,
"summary_ok": summary_ok,
"panel_ok": detail_ok,
"detail_ok": detail_ok,
"market_ok": market_ok,
"failed_count": len(failed),
"duration_ms": total_ms,
}
def get_system_cache_status(request: Request, cities: Optional[str] = None) -> Dict[str, Any]:
legacy_routes._assert_entitlement(request)
selected = legacy_routes._normalize_city_list(cities)
if not selected:
selected = list(legacy_routes.DEFAULT_PREWARM_CITIES)
selected = legacy_routes._normalize_city_list(None)
kinds = {
"summary": legacy_routes.CITY_SUMMARY_CACHE_TTL_SEC,
"panel": legacy_routes.CITY_PANEL_CACHE_TTL_SEC,