From 8292402fb402e2573edc410a26d2b60d8e3e72b8 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 20 Nov 2026 13:32:13 +0000 Subject: [PATCH] SO2 collector: damaged archive files don't block caching a month Every remaining 2021 failure (67) was an HDF5 decode error on a damaged file, which fails the same way on every run. Those are counted apart from transient failures, so a month like 2021-05 (11% damaged) is cached. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01NsPrq53XXinQsUZsWqeKht --- qtrade/data/sentinel5p.py | 8 ++++++-- tests/test_crm_so2_tracker.py | 9 ++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/qtrade/data/sentinel5p.py b/qtrade/data/sentinel5p.py index aee991082..8e9599b88 100644 --- a/qtrade/data/sentinel5p.py +++ b/qtrade/data/sentinel5p.py @@ -201,10 +201,13 @@ def run_isolated(jobs: list[tuple[dict, list[Site]]], workers: int, timeout_s: f (a damaged file, a dead connection) stalls every other thread - the 2021 run sat idle for five hours that way. A separate process per file can be killed when it overruns ``timeout_s``. ``before_fork(item)`` runs in the parent first (it fetches the storage token there, so the children - inherit it instead of each asking the signing service). ``stats["failed"]`` counts failed files. + inherit it instead of each asking the signing service). ``stats["failed"]`` counts files that failed + for a reason a later run may not hit (network, rate limit, timeout); ``stats["damaged"]`` counts + files whose HDF5 data could not be decoded. """ stats = stats if stats is not None else {} stats.setdefault("failed", 0) + stats.setdefault("damaged", 0) ctx = mp.get_context("fork") todo = list(jobs) running: dict = {} # parent conn -> (process, item id, start time) @@ -236,7 +239,8 @@ def run_isolated(jobs: list[tuple[dict, list[Site]]], workers: int, timeout_s: f yield val else: LOG.warning("s5p item %s failed: %s", iid, val) - stats["failed"] += 1 + # a damaged file in the archive fails the same way every time - no point refetching for it + stats["damaged" if "synchronously read" in str(val) else "failed"] += 1 yield [] now = time.time() for conn, (p, iid, t0) in list(running.items()): diff --git a/tests/test_crm_so2_tracker.py b/tests/test_crm_so2_tracker.py index 4799e3503..5498a799b 100644 --- a/tests/test_crm_so2_tracker.py +++ b/tests/test_crm_so2_tracker.py @@ -94,6 +94,8 @@ def _fake_child(conn, it, ss): import time as _t if it["id"] == "hang": _t.sleep(60) + elif it["id"] == "damaged": + conn.send(("err", "Can't synchronously read data (wrong B-tree signature)")) elif it["id"] == "bad": conn.send(("err", "filter returned failure")) else: @@ -106,15 +108,16 @@ def test_run_isolated_kills_hung_reads(): from qtrade.data import sentinel5p as S5 - jobs = [({"id": i}, []) for i in ("a", "hang", "bad", "b")] + jobs = [({"id": i}, []) for i in ("a", "hang", "bad", "b", "damaged")] t = _t.time() seen, stats = [], {} out = list(S5.run_isolated(jobs, workers=4, timeout_s=2, target=_fake_child, before_fork=lambda it: seen.append(it["id"]), stats=stats)) assert _t.time() - t < 20 - assert len(out) == 4 + assert len(out) == 5 assert sorted(r for rows in out for r in rows) == [("a", 1), ("b", 1)] - assert seen == ["a", "hang", "bad", "b"] and stats["failed"] == 2 + assert seen == ["a", "hang", "bad", "b", "damaged"] + assert stats["failed"] == 2 and stats["damaged"] == 1 def test_month_with_many_failures_is_not_cached(tmp_path, monkeypatch):