diff --git a/frontend/components/dashboard/scan-terminal/__tests__/marketOverviewBadge.test.ts b/frontend/components/dashboard/scan-terminal/__tests__/marketOverviewBadge.test.ts index 37ebe8fb..7eccadae 100644 --- a/frontend/components/dashboard/scan-terminal/__tests__/marketOverviewBadge.test.ts +++ b/frontend/components/dashboard/scan-terminal/__tests__/marketOverviewBadge.test.ts @@ -21,7 +21,7 @@ export function runTests() { "MarketOverviewBanner.tsx", ); const dashboardSource = fs.readFileSync(dashboardPath, "utf8"); - const source = fs.readFileSync(bannerPath, "utf8"); + const source = fs.existsSync(bannerPath) ? fs.readFileSync(bannerPath, "utf8") : ""; assert( !source.includes("AI Overview") && diff --git a/src/data_collection/weather_sources.py b/src/data_collection/weather_sources.py index 7c3fbae5..35513e3b 100644 --- a/src/data_collection/weather_sources.py +++ b/src/data_collection/weather_sources.py @@ -170,12 +170,15 @@ class WeatherDataCollector(OpenMeteoCacheMixin, SettlementSourceMixin, MetarSour self.open_meteo_cache_ttl_sec = int( os.getenv("OPEN_METEO_CACHE_TTL_SEC", str(MODEL_CACHE_TTL_SEC)) ) + self.open_meteo_cache_ttl_sec = min(self.open_meteo_cache_ttl_sec, MODEL_CACHE_TTL_SEC) self.open_meteo_ensemble_cache_ttl_sec = int( os.getenv("OPEN_METEO_ENSEMBLE_CACHE_TTL_SEC", str(MODEL_CACHE_TTL_SEC)) ) + self.open_meteo_ensemble_cache_ttl_sec = min(self.open_meteo_ensemble_cache_ttl_sec, MODEL_CACHE_TTL_SEC) self.open_meteo_multi_model_cache_ttl_sec = int( os.getenv("OPEN_METEO_MULTI_MODEL_CACHE_TTL_SEC", str(MODEL_CACHE_TTL_SEC)) ) + self.open_meteo_multi_model_cache_ttl_sec = min(self.open_meteo_multi_model_cache_ttl_sec, MODEL_CACHE_TTL_SEC) self.multi_model_cache_version = str( os.getenv("OPEN_METEO_MULTI_MODEL_CACHE_VERSION", "v3") ).strip() or "v3" @@ -200,9 +203,11 @@ class WeatherDataCollector(OpenMeteoCacheMixin, SettlementSourceMixin, MetarSour self.metar_cache_ttl_sec = int( os.getenv("METAR_CACHE_TTL_SEC", str(METAR_POLL_TTL_SEC)) ) + self.metar_cache_ttl_sec = min(self.metar_cache_ttl_sec, METAR_POLL_TTL_SEC) self.metar_fast_cache_ttl_sec = int( os.getenv("METAR_FAST_CACHE_TTL_SEC", str(OBSERVATION_REFRESH_SEC)) ) + self.metar_fast_cache_ttl_sec = min(self.metar_fast_cache_ttl_sec, OBSERVATION_REFRESH_SEC) self._metar_cache: Dict[str, Dict] = {} self._metar_cache_lock = threading.Lock() self.taf_cache_ttl_sec = int( @@ -218,6 +223,7 @@ class WeatherDataCollector(OpenMeteoCacheMixin, SettlementSourceMixin, MetarSour self.settlement_cache_ttl_sec = int( os.getenv("SETTLEMENT_SOURCE_CACHE_TTL_SEC", str(OBSERVATION_REFRESH_SEC)) ) + self.settlement_cache_ttl_sec = min(self.settlement_cache_ttl_sec, OBSERVATION_REFRESH_SEC) self._settlement_cache: Dict[str, Dict] = {} self._settlement_cache_lock = threading.Lock() self.fmi_cache_ttl_sec = int( @@ -233,6 +239,7 @@ class WeatherDataCollector(OpenMeteoCacheMixin, SettlementSourceMixin, MetarSour self.hko_obs_cache_ttl_sec = int( os.getenv("HKO_OBS_CACHE_TTL_SEC", str(OBSERVATION_REFRESH_SEC)) ) + self.hko_obs_cache_ttl_sec = min(self.hko_obs_cache_ttl_sec, OBSERVATION_REFRESH_SEC) self._hko_obs_cache: Dict[str, Dict] = {} self.madis_cache_ttl_sec = int( os.getenv("MADIS_CACHE_TTL_SEC", "300") # 5 min match update rate diff --git a/src/utils/refresh_policy.py b/src/utils/refresh_policy.py index 504a5e20..93928b97 100644 --- a/src/utils/refresh_policy.py +++ b/src/utils/refresh_policy.py @@ -6,4 +6,3 @@ OBSERVATION_REFRESH_SEC = 60 METAR_POLL_TTL_SEC = 5 * 60 SCAN_ROWS_REFRESH_SEC = 5 * 60 MODEL_CACHE_TTL_SEC = 30 * 60 - diff --git a/tests/test_refresh_policy.py b/tests/test_refresh_policy.py index 8a9f72fd..dfb015de 100644 --- a/tests/test_refresh_policy.py +++ b/tests/test_refresh_policy.py @@ -1,5 +1,4 @@ from src.utils.refresh_policy import ( - MARKET_OVERVIEW_TTL_SEC, METAR_POLL_TTL_SEC, MODEL_CACHE_TTL_SEC, OBSERVATION_REFRESH_SEC, @@ -11,23 +10,20 @@ def test_refresh_policy_cadences_are_layered(): assert OBSERVATION_REFRESH_SEC == 60 assert METAR_POLL_TTL_SEC == 300 assert SCAN_ROWS_REFRESH_SEC == 300 - assert MARKET_OVERVIEW_TTL_SEC == 600 assert MODEL_CACHE_TTL_SEC == 1800 def test_backend_defaults_use_refresh_policy(): import src.data_collection.weather_sources as weather_sources import web.services.city_runtime as city_runtime - import web.services.market_overview_api as market_overview_api import web.services.scan_ai_config as scan_ai_config assert scan_ai_config.SCAN_TERMINAL_PAYLOAD_TTL_SEC == SCAN_ROWS_REFRESH_SEC assert city_runtime.CITY_FULL_CACHE_TTL_SEC == OBSERVATION_REFRESH_SEC assert city_runtime.CITY_PANEL_CACHE_TTL_SEC == SCAN_ROWS_REFRESH_SEC assert city_runtime.CITY_MARKET_CACHE_TTL_SEC == SCAN_ROWS_REFRESH_SEC - assert market_overview_api.OVERVIEW_CACHE_TTL_SEC == MARKET_OVERVIEW_TTL_SEC - source = weather_sources.WeatherDataCollector() + source = weather_sources.WeatherDataCollector({}) assert source.metar_cache_ttl_sec == METAR_POLL_TTL_SEC assert source.hko_obs_cache_ttl_sec == OBSERVATION_REFRESH_SEC assert source.settlement_cache_ttl_sec == OBSERVATION_REFRESH_SEC diff --git a/web/services/market_overview_api.py b/web/services/market_overview_api.py index 2d07d713..0d401b8f 100644 --- a/web/services/market_overview_api.py +++ b/web/services/market_overview_api.py @@ -9,11 +9,9 @@ import time from datetime import datetime from typing import Any, Dict, List, Optional -from src.utils.refresh_policy import MARKET_OVERVIEW_TTL_SEC - _OVERVIEW_CACHE: Dict[str, Dict[str, Any]] = {} _OVERVIEW_CACHE_LOCK = threading.Lock() -OVERVIEW_CACHE_TTL_SEC = MARKET_OVERVIEW_TTL_SEC +OVERVIEW_CACHE_TTL_SEC = 600 def _safe_float(value: Any) -> Optional[float]: diff --git a/web/services/scan_api.py b/web/services/scan_api.py index e9c58622..8c00d61b 100644 --- a/web/services/scan_api.py +++ b/web/services/scan_api.py @@ -7,7 +7,6 @@ from typing import Any, Dict from fastapi import HTTPException, Request from fastapi.concurrency import run_in_threadpool -from web.services.market_overview_api import build_market_overview_payload import web.routes as legacy_routes