修复 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:
@@ -359,6 +359,13 @@ class NwsOpenMeteoSourceMixin:
|
||||
if stale and isinstance(stale.get("data"), dict):
|
||||
record_source_call("open_meteo", "forecast", "stale_cache", (time.perf_counter() - started) * 1000.0)
|
||||
return dict(stale["data"])
|
||||
# Memory miss: force-reload from disk and retry once
|
||||
self._load_open_meteo_disk_cache()
|
||||
with self._open_meteo_cache_lock:
|
||||
stale2 = self._open_meteo_cache.get(cache_key)
|
||||
if stale2 and isinstance(stale2.get("data"), dict):
|
||||
record_source_call("open_meteo", "forecast", "disk_fallback", (time.perf_counter() - started) * 1000.0)
|
||||
return dict(stale2["data"])
|
||||
record_source_call("open_meteo", "forecast", "cooldown_skip", (time.perf_counter() - started) * 1000.0)
|
||||
return None
|
||||
with self._open_meteo_cache_lock:
|
||||
@@ -528,9 +535,15 @@ class NwsOpenMeteoSourceMixin:
|
||||
if stale and isinstance(stale.get("data"), dict):
|
||||
record_source_call("open_meteo", "ensemble", "stale_cache", (time.perf_counter() - started) * 1000.0)
|
||||
return dict(stale["data"])
|
||||
self._load_open_meteo_disk_cache()
|
||||
with self._ensemble_cache_lock:
|
||||
stale2 = self._ensemble_cache.get(cache_key)
|
||||
if stale2 and isinstance(stale2.get("data"), dict):
|
||||
record_source_call("open_meteo", "ensemble", "disk_fallback", (time.perf_counter() - started) * 1000.0)
|
||||
return dict(stale2["data"])
|
||||
record_source_call("open_meteo", "ensemble", "cooldown_skip", (time.perf_counter() - started) * 1000.0)
|
||||
return None
|
||||
|
||||
|
||||
with self._ensemble_cache_lock:
|
||||
cached = self._ensemble_cache.get(cache_key)
|
||||
if (
|
||||
@@ -685,6 +698,12 @@ class NwsOpenMeteoSourceMixin:
|
||||
if stale and isinstance(stale.get("data"), dict):
|
||||
record_source_call("open_meteo", "multi_model", "stale_cache", (time.perf_counter() - started) * 1000.0)
|
||||
return dict(stale["data"])
|
||||
self._load_open_meteo_disk_cache()
|
||||
with self._multi_model_cache_lock:
|
||||
stale2 = self._multi_model_cache.get(cache_key)
|
||||
if stale2 and isinstance(stale2.get("data"), dict):
|
||||
record_source_call("open_meteo", "multi_model", "disk_fallback", (time.perf_counter() - started) * 1000.0)
|
||||
return dict(stale2["data"])
|
||||
record_source_call("open_meteo", "multi_model", "cooldown_skip", (time.perf_counter() - started) * 1000.0)
|
||||
return None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user