Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions qtrade/data/sentinel5p.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()):
Expand Down
9 changes: 6 additions & 3 deletions tests/test_crm_so2_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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):
Expand Down
Loading