fix(weather): resilient per-zone/multi-city weather under Open-Meteo 429#378
Merged
Merged
Conversation
…o 429 Per-zone weather (22.4.0) fetches many cities; a burst trips Open-Meteo's archive rate limit (429). Two problems are fixed: 1. Catchable failure. When a 429 sends one city to differently-ranged fallback data, population_weighted_average raises a bare ValueError that escaped on_weather_failure="skip" and crashed the run. The multi-city combine now re-raises it as WeatherFetchError (a ValueError subclass), so the configured skip/raise policy governs it — "skip" degrades to no-weather instead of crashing. 2. Throttling. A process-wide minimum spacing between Open-Meteo requests (_throttle_open_meteo; default 0.5 s, env SPOTFORECAST2_WEATHER_MIN_REQUEST_INTERVAL) spreads the per-zone burst under the limit; the urllib3 retry is bumped to total=5/backoff=2 and honours Retry-After. Affects request timing only, never the data — determinism preserved. tests/conftest.py disables the throttle for the network-mocked suite. New tests cover the ValueError->WeatherFetchError conversion and the throttle spacing. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
| wait = _MIN_REQUEST_INTERVAL_S - (monotonic() - _LAST_REQUEST_MONOTONIC) | ||
| if wait > 0: | ||
| sleep(wait) | ||
| _LAST_REQUEST_MONOTONIC = monotonic() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Hotfix for the 22.4.0 per-zone weather feature. A real four-zone run with
--per-zone-weathercrashed with:The
ValueErrorescapedon_weather_failure="skip"and aborted the run.Fix (two parts)
population_weighted_averageraises a bareValueError. The multi-city combine inweather/features.pynow re-raises it asWeatherFetchError(aValueErrorsubclass), so the configured skip/raise policy governs it —"skip"degrades to no-weather instead of crashing._throttle_open_meteo; default 0.5 s, envSPOTFORECAST2_WEATHER_MIN_REQUEST_INTERVAL) spreads the per-zone burst under the rate limit. The urllib3 retry is bumped tototal=5/backoff=2and honoursRetry-After. Request timing only — never the data, so determinism is preserved.tests/conftest.pydisables the throttle for the network-mocked suite. New tests cover theValueError→WeatherFetchErrorconversion and the throttle spacing.Verification (all green locally)
uv run pytest tests/ -q— 2638 passed, 1 skippeduv run ruff check src/ tests/— cleanuv run reuse lint— cleanuv run quartodoc build && quartodoc interlinks && quarto render --no-cache— full site render, exit 0Internal-only fix; no public API surface change.
🤖 Generated with Claude Code