Use longer timeout for scan prewarm
This commit is contained in:
@@ -72,7 +72,15 @@ def test_scan_terminal_backend_timeout_returns_before_next_proxy_abort():
|
||||
|
||||
assert 'POLYWEATHER_SCAN_TERMINAL_PROXY_TIMEOUT_MS || "18000"' in route_source
|
||||
assert '"POLYWEATHER_SCAN_TERMINAL_BUILD_TIMEOUT_SEC",\n 10,' in config_source
|
||||
assert (
|
||||
'"POLYWEATHER_SCAN_TERMINAL_PREWARM_PAYLOAD_TIMEOUT_SEC",\n 30,'
|
||||
in config_source
|
||||
)
|
||||
assert scan_terminal_config.SCAN_TERMINAL_BUILD_TIMEOUT_SEC <= 30
|
||||
assert (
|
||||
scan_terminal_config.SCAN_TERMINAL_PREWARM_PAYLOAD_TIMEOUT_SEC
|
||||
>= scan_terminal_config.SCAN_TERMINAL_BUILD_TIMEOUT_SEC
|
||||
)
|
||||
|
||||
|
||||
def test_probability_engine_uses_enriched_multi_model_snapshot():
|
||||
|
||||
@@ -2301,8 +2301,8 @@ def test_scan_terminal_timeout_does_not_replace_better_cached_snapshot(monkeypat
|
||||
def test_scan_terminal_prewarm_builds_default_terminal_payload(monkeypatch):
|
||||
calls = []
|
||||
|
||||
def _fake_build(filters, *, force_refresh=False):
|
||||
calls.append((dict(filters), force_refresh))
|
||||
def _fake_build(filters, *, force_refresh=False, timeout_sec=None):
|
||||
calls.append((dict(filters), force_refresh, timeout_sec))
|
||||
return {"rows": []}
|
||||
|
||||
monkeypatch.setattr(
|
||||
@@ -2312,8 +2312,9 @@ def test_scan_terminal_prewarm_builds_default_terminal_payload(monkeypatch):
|
||||
)
|
||||
|
||||
assert scan_terminal_service._warm_scan_terminal_payloads() == 1
|
||||
filters, force_refresh = calls[0]
|
||||
filters, force_refresh, timeout_sec = calls[0]
|
||||
assert force_refresh is False
|
||||
assert timeout_sec == scan_terminal_service.SCAN_TERMINAL_PREWARM_PAYLOAD_TIMEOUT_SEC
|
||||
assert filters["scan_mode"] == "tradable"
|
||||
assert filters["min_price"] == 0.05
|
||||
assert filters["max_price"] == 0.95
|
||||
|
||||
@@ -16,6 +16,7 @@ from web.services.scan_terminal_config import (
|
||||
SCAN_TERMINAL_BUILD_TIMEOUT_SEC,
|
||||
SCAN_TERMINAL_MAX_WORKERS,
|
||||
SCAN_TERMINAL_PAYLOAD_TTL_SEC,
|
||||
SCAN_TERMINAL_PREWARM_PAYLOAD_TIMEOUT_SEC,
|
||||
)
|
||||
from src.data_collection.city_registry import ALIASES
|
||||
from web.scan_terminal_cache import (
|
||||
@@ -101,11 +102,17 @@ def _build_scan_terminal_payload_uncached(
|
||||
filters: Dict[str, Any],
|
||||
*,
|
||||
force_refresh: bool = False,
|
||||
timeout_sec: Optional[float] = None,
|
||||
) -> Dict[str, Any]:
|
||||
cached_entry = get_scan_terminal_cache_entry(filters) or {}
|
||||
|
||||
try:
|
||||
city_names = list(CITIES.keys())
|
||||
build_timeout_sec = float(
|
||||
timeout_sec
|
||||
if timeout_sec is not None
|
||||
else SCAN_TERMINAL_BUILD_TIMEOUT_SEC
|
||||
)
|
||||
timezone_offset = filters.get("timezone_offset_seconds")
|
||||
if timezone_offset is not None:
|
||||
target_tz = int(timezone_offset)
|
||||
@@ -145,7 +152,7 @@ def _build_scan_terminal_payload_uncached(
|
||||
try:
|
||||
completed = as_completed(
|
||||
future_map,
|
||||
timeout=float(SCAN_TERMINAL_BUILD_TIMEOUT_SEC),
|
||||
timeout=build_timeout_sec,
|
||||
)
|
||||
for future in completed:
|
||||
city_name = future_map[future]
|
||||
@@ -160,8 +167,7 @@ def _build_scan_terminal_payload_uncached(
|
||||
except FutureTimeoutError:
|
||||
timed_out = True
|
||||
timeout_message = (
|
||||
f"scan terminal build timed out after "
|
||||
f"{SCAN_TERMINAL_BUILD_TIMEOUT_SEC}s"
|
||||
f"scan terminal build timed out after {build_timeout_sec:g}s"
|
||||
)
|
||||
failed_reasons.append(timeout_message)
|
||||
for future, city_name in future_map.items():
|
||||
@@ -361,7 +367,11 @@ def _warm_scan_terminal_payloads() -> int:
|
||||
ok = 0
|
||||
for filters in _scan_terminal_prewarm_filters():
|
||||
try:
|
||||
_build_scan_terminal_payload_uncached(filters, force_refresh=False)
|
||||
_build_scan_terminal_payload_uncached(
|
||||
filters,
|
||||
force_refresh=False,
|
||||
timeout_sec=SCAN_TERMINAL_PREWARM_PAYLOAD_TIMEOUT_SEC,
|
||||
)
|
||||
ok += 1
|
||||
except Exception as exc:
|
||||
logger.warning("scan terminal payload pre-warm failed: {}", exc)
|
||||
|
||||
@@ -35,6 +35,12 @@ SCAN_TERMINAL_BUILD_TIMEOUT_SEC = _env_int(
|
||||
min_value=8,
|
||||
max_value=30,
|
||||
)
|
||||
SCAN_TERMINAL_PREWARM_PAYLOAD_TIMEOUT_SEC = _env_int(
|
||||
"POLYWEATHER_SCAN_TERMINAL_PREWARM_PAYLOAD_TIMEOUT_SEC",
|
||||
30,
|
||||
min_value=10,
|
||||
max_value=120,
|
||||
)
|
||||
SCAN_TERMINAL_MAX_WORKERS = _env_int(
|
||||
"POLYWEATHER_SCAN_TERMINAL_MAX_WORKERS",
|
||||
8,
|
||||
|
||||
Reference in New Issue
Block a user