Fallout winds: make the daily download at 23 past the hour (#1020)
Some checks failed
Backend Tests / api-tests (core) (push) Has been cancelled
Backend Tests / api-tests (files) (push) Has been cancelled
Backend Tests / api-tests (media) (push) Has been cancelled
Backend Tests / api-tests (rest) (push) Has been cancelled
Backend Tests / api-contract-tests (push) Has been cancelled
Backend Tests / api-migrations-and-start (push) Has been cancelled
CodeQL / Analyze (push) Has been cancelled
Controller Tests / controller-tests (push) Has been cancelled
Cypress Tests / cypress-component-tests (push) Has been cancelled
Cypress Tests / cypress-e2e-tests (push) Has been cancelled
Dead Code / vulture (push) Has been cancelled
Jest Tests / jest-tests (push) Has been cancelled

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 <noreply@anthropic.com>
This commit is contained in:
lrnselfreliance 2026-11-26 17:23:54 -07:00 • committed by GitHub
parent f58c86af88
commit 68d8eadd69
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 26 additions and 1 deletions

View file

@ -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."""

View file

@ -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()