fix: retry transient official source failures
GeoIntel CI / docs-smoke (push) Canceled after 0s
GeoIntel CI / contract-smoke (push) Canceled after 0s

This commit is contained in:
Codex
2026-07-14 05:47:06 +02:00
parent 480634c301
commit e8a35b96ad
4 changed files with 38 additions and 2 deletions
@@ -17,10 +17,12 @@ from pathlib import Path
from typing import Any, Iterable
import requests
from requests.adapters import HTTPAdapter
from pyproj import Transformer
from shapely.geometry import GeometryCollection, MultiPolygon, Polygon, mapping, shape
from shapely.ops import transform, unary_union
from shapely.validation import make_valid
from urllib3.util.retry import Retry
MUNICIPALITY_NAME = "Mol"
@@ -40,6 +42,7 @@ DEFAULT_API_URL = "http://127.0.0.1:8000"
DEFAULT_PAGE_LIMIT = 1000
DEFAULT_MAX_FEATURES = 100000
GEOJSON_CRS = {"type": "name", "properties": {"name": "EPSG:4326"}}
RETRYABLE_SOURCE_STATUS_CODES = (429, 500, 502, 503, 504)
def parse_args() -> argparse.Namespace:
@@ -116,6 +119,25 @@ def write_json(path: Path, payload: dict[str, Any], *, pretty: bool = False) ->
)
def build_source_session() -> requests.Session:
retry = Retry(
total=5,
connect=5,
read=5,
status=5,
backoff_factor=1.0,
status_forcelist=RETRYABLE_SOURCE_STATUS_CODES,
allowed_methods=frozenset({"GET"}),
raise_on_status=True,
)
adapter = HTTPAdapter(max_retries=retry)
session = requests.Session()
session.headers.update({"User-Agent": "GeoIntel-Mol-Municipality-Operator/1.0"})
session.mount("https://", adapter)
session.mount("http://", adapter)
return session
def next_page_url(payload: dict[str, Any]) -> str | None:
links = payload.get("links") or []
for link in links:
@@ -319,8 +341,7 @@ def prepare_artifacts(args: argparse.Namespace) -> tuple[Path, Path, dict[str, A
if args.page_limit <= 0 or args.max_features <= 0:
raise RuntimeError("--page-limit and --max-features must be positive integers")
with requests.Session() as session:
session.headers.update({"User-Agent": "GeoIntel-Mol-Municipality-Operator/1.0"})
with build_source_session() as session:
boundary_feature, boundary, boundary_source_url = fetch_mol_boundary(session, args.request_timeout)
buildings, building_summary = build_municipality_buildings(
iter_grb_pages(