From 1c0d8b44a0be2f72695ebc1d04fef115121ae14d Mon Sep 17 00:00:00 2001 From: Nick Sweeting Date: Fri, 15 May 2026 10:06:24 -0700 Subject: [PATCH] Find snapshot completion events through bus history --- archivebox/services/runner.py | 13 ++++++------- archivebox/tests/test_runner.py | 26 ++++++++++++++++++++++++++ pyproject.toml | 2 +- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/archivebox/services/runner.py b/archivebox/services/runner.py index d70f16d8..c5e34ac0 100644 --- a/archivebox/services/runner.py +++ b/archivebox/services/runner.py @@ -583,14 +583,13 @@ class CrawlRunner: ) emitted_snapshot_event = self.bus.emit(snapshot_event) await emitted_snapshot_event.now() - await emitted_snapshot_event.event_results_list() - snapshot_event_results = getattr(snapshot_event, "event_results", {}) - snapshot_event_children = getattr(snapshot_event, "event_children", []) - completed_snapshot = next( - (child for child in snapshot_event_children if isinstance(child, SnapshotCompletedEvent)), - None, + completed_snapshot = await self.bus.find( + SnapshotCompletedEvent, + child_of=emitted_snapshot_event, + past=True, + future=snapshot_phase_timeout, ) - if snapshot_event_results and completed_snapshot is None: + if completed_snapshot is None: raise RuntimeError(f"Snapshot {snapshot_id} did not complete") await self.enqueue_discovered_snapshots_from_outputs(snapshot) finally: diff --git a/archivebox/tests/test_runner.py b/archivebox/tests/test_runner.py index 07c18042..13ec5fb4 100644 --- a/archivebox/tests/test_runner.py +++ b/archivebox/tests/test_runner.py @@ -28,9 +28,24 @@ class _DummyBus: def emit(self, event): self.emitted.append(event) + bus = self class _Pending: + def __getattr__(self, name): + return getattr(event, name) + async def now(self, *args, **kwargs): + from abx_dl.events import SnapshotCompletedEvent, SnapshotEvent + + if isinstance(event, SnapshotEvent): + bus.emitted.append( + SnapshotCompletedEvent( + url=event.url, + snapshot_id=event.snapshot_id, + output_dir=event.output_dir, + event_parent_id=event.event_id, + ), + ) return event async def wait(self, *args, **kwargs): @@ -41,6 +56,17 @@ class _DummyBus: return _Pending() + async def find(self, event_type, where=None, child_of=None, **kwargs): + for event in reversed(self.emitted): + if not isinstance(event, event_type): + continue + if child_of is not None and event.event_parent_id != child_of.event_id: + continue + if where is not None and not where(event): + continue + return event + return None + async def stop(self): return None diff --git a/pyproject.toml b/pyproject.toml index 8adc2df9..65a7ac20 100755 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "archivebox" -version = "0.9.30rc19" +version = "0.9.30rc20" requires-python = ">=3.13" description = "Self-hosted internet archiving solution." authors = [{name = "Nick Sweeting", email = "pyproject.toml@archivebox.io"}]