fix(ext): устойчивость чекера + точный фильтр XSD-схем (фиксы Fable Фазы 4/5)
- run_check: каждый источник в _safe_check — ЛЮБОЙ сбой (не только FetchError) становится problem-находкой, а не убивает весь прогон (отчёт/письмо/heartbeat). - run_check: неблокирующий .check.lock — наложение cron-прогонов пропускается, а не плодит дубль работы и писем. - run_check: EXT_REGIONS=all, но список субъектов не получен → problem (факт), а не тихое «не задан». - xsd_client: фильтр схем сверен с живой страницей Минстроя (151 .zip). Убран слишком широкий маркер skhema/схема — цеплял «схему пояснительной записки проекта». Берём только сметные/экспертизные схемы, отсекаем журналы/акты. - Тесты: баг-в-чекере→problem, all-но-недоступен→problem, наложение→skip, реальные имена файлов в XSD-тестах. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -79,8 +79,29 @@ def fetch_json(url: str, params: dict | None = None, *, client: httpx.Client | N
|
||||
raise FetchError(f"fetch_json {url}: {type(last).__name__}: {last}")
|
||||
|
||||
|
||||
def fetch_text(url: str, params: dict | None = None, *, client: httpx.Client | None = None) -> str:
|
||||
"""GET → текст (HTML), с ретраями и конвертацией httpx-ошибок в FetchError (иначе
|
||||
сырое httpx-исключение пролетело бы мимо except FetchError и уронило вызывающего)."""
|
||||
last: Exception | None = None
|
||||
for attempt in range(RETRIES):
|
||||
c = client or make_client()
|
||||
try:
|
||||
r = c.get(url, params=params)
|
||||
r.raise_for_status()
|
||||
return r.text
|
||||
except httpx.HTTPError as e:
|
||||
last = e
|
||||
if attempt < RETRIES - 1:
|
||||
_sleep_backoff(attempt)
|
||||
finally:
|
||||
if client is None:
|
||||
c.close()
|
||||
raise FetchError(f"fetch_text {url}: {type(last).__name__}: {last}")
|
||||
|
||||
|
||||
def fetch_file(url: str, dest: os.PathLike | str, *, params: dict | None = None,
|
||||
expect_min_size: int = 1, expected_content_type: str | None = None,
|
||||
reject_content_type: str | None = None,
|
||||
client: httpx.Client | None = None) -> dict:
|
||||
"""Потоково скачать в dest (через *.part). Возвращает {path, size, sha256}.
|
||||
fail-loud: мал/не тот тип → FetchError, dest не создан (остаётся .part для разбора)."""
|
||||
@@ -100,6 +121,8 @@ def fetch_file(url: str, dest: os.PathLike | str, *, params: dict | None = None,
|
||||
ct = r.headers.get("content-type", "")
|
||||
if expected_content_type and expected_content_type not in ct:
|
||||
raise FetchError(f"неожиданный content-type {ct!r} (ждали {expected_content_type!r})")
|
||||
if reject_content_type and reject_content_type in ct:
|
||||
raise FetchError(f"отклонён content-type {ct!r} (страница ошибки вместо данных?)")
|
||||
with open(part, "wb") as f:
|
||||
for chunk in r.iter_bytes(1 << 16):
|
||||
f.write(chunk)
|
||||
|
||||
Reference in New Issue
Block a user