refactor(progress): return bound callable from start_download (#30)

start_download(book) now returns a per-book bound callable
instead of raw task_id. Task identity is fully internal to
progress.py — no caller ever sees or passes task_id.

- Orchestrator: removed closure pattern, now threads
  progress_cb = start_download(book) directly
- downloader: download_book() accepts optional progress= kwarg,
  uses it when provided (falls back to reporter.update)
- cli.py: forwards progress kwarg through _download_fn
- Public update() drops task_id param; bound callable calls
  _progress.update(task_id_internal) directly

382 tests pass (+11 new), 6/6 AC met.
This commit is contained in:
AlexKucera committed 2026-06-05 11:58:04 +02:00
1 parent 9ac581e5b7
commit 1f46467f2c
10 files changed
+398 -95

No files matched your search

+5 -9
View File
@@ -69,17 +69,13 @@ def _download_one(
- error: exception string if download_fn raised, else None
- was_skipped: True if download_fn returned None (skipped)
"""
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)
# Issue #30: start_download() returns a bound callable that already carries
# task identity internally. For TTY reporters this is a per-book update fn;
# for plain-text reporters it is None. No closure needed here.
progress_cb = reporter.start_download(book)
try:
result = download_fn(book, progress=_progress)
result = download_fn(book, progress=progress_cb)
if result is None:
# Skipped (no format available)
reporter.complete(book) # still "complete" the progress tracking