From 68d8eadd699a693c81bb2cbd777d65c5bc6ffff7 Mon Sep 17 00:00:00 2001 From: lrnselfreliance <33263708+lrnselfreliance@users.noreply.github.com> Date: Thu, 26 Nov 2026 17:23:54 -0700 Subject: [PATCH] Fallout winds: make the daily download at 23 past the hour (#1020) Daily downloads are spread over the day in slots which fall on the hour, when the forecast service is busiest. On .5 its TLS handshake stalled for minutes there, failing the download. The weather downloader now schedules its next run itself, a day later at 23 minutes past the hour. Co-authored-by: Claude Opus 5.5 --- modules/map/test/test_winds.py | 16 ++++++++++++++++ modules/map/winds.py | 11 ++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/modules/map/test/test_winds.py b/modules/map/test/test_winds.py index 7902cad0..627d7cd3 100644 --- a/modules/map/test/test_winds.py +++ b/modules/map/test/test_winds.py @@ -1,4 +1,5 @@ import json +from datetime import datetime, timedelta from http import HTTPStatus from unittest import mock @@ -320,6 +321,21 @@ async def test_weather_subscription(async_client, test_session, test_directory, assert response.status_code == HTTPStatus.BAD_REQUEST +@pytest.mark.parametrize('finished,expected', [ + ('2026-11-27T00:07:30+00:00', '2026-11-28T00:23:00+00:00'), + ('2026-11-27T14:00:11+00:00', '2026-11-28T14:23:00+00:00'), + ('2026-11-27T14:59:59+00:00', '2026-11-28T14:23:00+00:00'), +]) +def test_weather_downloader_avoids_the_hour(finished, expected): + """The next day's download is at WEATHER_MINUTE past an hour, when the forecast service is not + busy with requests made on the hour.""" + with mock.patch('modules.map.winds.now', lambda: datetime.fromisoformat(finished)): + result = winds.weather_downloader.finalize_download(None, None, winds.ExecutedWeather(points=1)) + assert result.success is True + assert datetime.fromisoformat(finished) + timedelta(seconds=result.retry_seconds) \ + == datetime.fromisoformat(expected) + + @pytest.mark.asyncio async def test_weather_downloader(test_session, test_directory, test_nuclear_config): """The downloader fetches a field around the saved targets, telling how far it has got.""" diff --git a/modules/map/winds.py b/modules/map/winds.py index ea822a2e..3d2fa914 100644 --- a/modules/map/winds.py +++ b/modules/map/winds.py @@ -20,6 +20,7 @@ a whole country takes a few minutes. import asyncio import json from dataclasses import dataclass +from datetime import timedelta import time import math from pathlib import Path @@ -299,6 +300,9 @@ _summary_cache = dict() # The weather subscription: one recurring Download of a field around the saved targets. WEATHER_URL = OPEN_METEO_URL WEATHER_DOWNLOADER = 'open_meteo' +# The minute past the hour the daily download is made: the forecast service is busy with requests +# made on the hour, sometimes too busy to answer a connection for minutes. +WEATHER_MINUTE = 23 def target_places() -> List[Tuple[float, float]]: @@ -403,7 +407,12 @@ class WeatherDownloader(Downloader): def finalize_download(self, session: Session, download: Download, executed: ExecutedWeather) -> DownloadResult: if executed.error: return DownloadResult(success=False, error=executed.error) - return DownloadResult(success=True, location='/map/manage') + # The next day's download is at WEATHER_MINUTE past the hour this one finished in, rather than in + # a daily slot (which are on the hour). + finished = now() + tomorrow = (finished + timedelta(days=1)).replace(minute=WEATHER_MINUTE, second=0, microsecond=0) + return DownloadResult(success=True, location='/map/manage', + retry_seconds=int((tomorrow - finished).total_seconds())) weather_downloader = WeatherDownloader()