修复 Open-Meteo 冷却期无限循环导致多模型数据缺失

- fetch_all_sources 新增 om_from_cache_only 模式:force_refresh_observations_only
  时直接从内存缓存取 OM 数据,不发起 HTTP 请求。缓存未命中则跳过,
  避免机场推送 60s 周期持续触发 429 限流
- nws_open_meteo_sources 三类 fetch 函数冷却期加磁盘缓存兜底:
  内存未命中时 force-reload SQLite 磁盘缓存再查一次
- 预热停止后冷却期自然过期(900s),下一次正常请求会填充缓存
This commit is contained in:
2569718930@qq.com
2026-05-17 22:31:10 +08:00
parent 415f03466d
commit 22e2409e13
4 changed files with 98 additions and 18 deletions
+23
View File
@@ -0,0 +1,23 @@
"""Check which cities have hourly / multi-model data in the analysis cache."""
import urllib.request, json
TOK = "Bearer ZLuvwSsQvHSj2geIWfX7gjn9rJU_heOlgq0FBp7cUOgXaB2eHbE20R4PKwonP2FP"
CITIES = [
"london", "paris", "amsterdam", "helsinki", "istanbul", "ankara",
"moscow", "new york", "los angeles", "chicago", "miami", "houston",
"lagos", "jeddah", "karachi", "tel aviv",
]
for city in CITIES:
url = f"http://localhost:8000/api/city/{city}/detail?force_refresh=false"
req = urllib.request.Request(url, headers={"Authorization": TOK})
try:
r = urllib.request.urlopen(req, timeout=30)
d = json.loads(r.read())
except Exception as e:
print(f"{city}: FAILED {e}")
continue
h = d.get("timeseries", {}).get("hourly", {})
m = d.get("models", {})
deb = d.get("deb", {})
print(f"{city}: hourly={len(h.get('times',[]))}p models={len(m)} deb={deb.get('prediction')}")
+14
View File
@@ -0,0 +1,14 @@
"""Check which cities have Open-Meteo cache entries in the web container."""
import time
from src.data_collection.weather_sources import WeatherDataCollector
from src.utils.config_loader import load_config
w = WeatherDataCollector(load_config())
print("Multi-model cache entries:")
for k in sorted(w._multi_model_cache.keys()):
age = int(time.time() - w._multi_model_cache[k].get("t", 0))
print(f" {k} age={age}s")
print(f"\nOM cache entries: {len(w._open_meteo_cache)}")
print(f"Multi-model cache entries: {len(w._multi_model_cache)}")
print(f"Rate limit until: {w._open_meteo_rate_limit_until}")