Fallout winds: retry a batch once when the forecast service can't be connected to (#1019)
Some checks are pending
Backend Tests / api-tests (core) (push) Waiting to run
Backend Tests / api-tests (files) (push) Waiting to run
Backend Tests / api-tests (media) (push) Waiting to run
Backend Tests / api-tests (rest) (push) Waiting to run
Backend Tests / api-contract-tests (push) Waiting to run
Backend Tests / api-migrations-and-start (push) Waiting to run
CodeQL / Analyze (push) Waiting to run
Controller Tests / controller-tests (push) Waiting to run
Cypress Tests / cypress-component-tests (push) Waiting to run
Cypress Tests / cypress-e2e-tests (push) Waiting to run
Dead Code / vulture (push) Waiting to run
Jest Tests / jest-tests (push) Waiting to run

A connection failure on any batch failed the whole daily download, discarding the
batches already fetched and deferring the field to the next day.  A batch which can't
connect is now asked again a minute later, once, as an HTTP 429 already is.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
lrnselfreliance 2026-11-26 09:02:48 -07:00 • committed by Roland
parent 4c9f413322
commit f58c86af88
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
2 changed files with 44 additions and 2 deletions

View file

@ -26,6 +26,7 @@ from pathlib import Path
from typing import List, Optional, Sequence, Tuple
from urllib.parse import urlencode
import aiohttp
from sqlalchemy.orm import Session
from modules.map.lib import get_map_directory
@ -195,7 +196,8 @@ async def request_forecast(url: str) -> list:
async def request_batch(url: str) -> list:
"""The forecasts of a request; asked once more, a minute later, when the service says too many
have been asked of it."""
have been asked of it, or could not be connected to (so the batches already fetched are not lost
to a moment's outage)."""
for attempt in range(2):
try:
return await request_forecast(url)
@ -207,7 +209,11 @@ async def request_batch(url: str) -> list:
except asyncio.TimeoutError as e:
raise WindsError(f'The forecast service did not answer within {TIMEOUT} seconds') from e
except Exception as e:
raise WindsError(f'Could not reach the forecast service: {str(e) or type(e).__name__}') from e
error = WindsError(f'Could not reach the forecast service: {str(e) or type(e).__name__}')
if attempt or not isinstance(e, aiohttp.ClientConnectionError):
raise error from e
logger.warning(f'{error}; trying again in a minute')
await asyncio.sleep(BATCH_SECONDS)
async def fetch_wind_field(places: Sequence[Tuple[float, float]], progress=None, cancelled=None) -> dict: