fix(progress): wire task_id through parallel progress callback
In parallel download mode, all progress updates went to the same (most recently started) bar because task_id was never threaded from start_download() to the update callback. Create per-book closure in orchestrator that binds task_id, pass through cli._download_fn as optional kwarg. 3 new regression tests. 259 total.
This commit is contained in:
1 parent
83254750e6
commit
75a6eb61ea
7 files changed
+301
-25
No files matched your search
@@ -148,7 +148,11 @@ def run(
|
||||
|
||||
def _make_download_fn():
|
||||
"""Closure capturing client, config, history, reporter for each book."""
|
||||
def _download_fn(book: Book):
|
||||
def _download_fn(book: Book, *, progress: "Callable[[int], None] | None" = None):
|
||||
# Allow orchestrator to inject a per-book bound progress callback.
|
||||
# Falls back to the shared reporter.update when not in parallel mode.
|
||||
if progress is None:
|
||||
progress = reporter.update
|
||||
return download_book(
|
||||
book=book,
|
||||
client=client,
|
||||
@@ -156,7 +160,7 @@ def run(
|
||||
history=history,
|
||||
format_strategy=config.format,
|
||||
config=config,
|
||||
progress=reporter.update,
|
||||
progress=progress,
|
||||
cancel_event=cancel_event,
|
||||
)
|
||||
return _download_fn
|
||||
|
||||
@@ -90,9 +90,17 @@ def _download_one(
|
||||
- error: exception string if download_fn raised, else None
|
||||
- was_skipped: True if download_fn returned None (skipped)
|
||||
"""
|
||||
reporter.start_download(book)
|
||||
task_id = reporter.start_download(book)
|
||||
|
||||
# Create a per-book progress callback bound to this book's task_id.
|
||||
# Without this, reporter.update() falls back to the most-recently-started
|
||||
# bar (see ProgressReporter.update), so all parallel downloads would
|
||||
# update the same progress bar.
|
||||
def _progress(completed: int, *, total: int | None = None) -> None:
|
||||
reporter.update(completed, total=total, task_id=task_id)
|
||||
|
||||
try:
|
||||
result = download_fn(book)
|
||||
result = download_fn(book, progress=_progress)
|
||||
if result is None:
|
||||
# Skipped (no format available)
|
||||
reporter.complete(book) # still "complete" the progress tracking
|
||||
|
||||
Reference in new issue
Block a user