New orchestrator.py module that encapsulates the ThreadPoolExecutor lifecycle for parallel book downloads. This is the core parallelism engine -- it replaces the sequential for loop in cli.py:run() with a thread-pool-based concurrent execution model.
Interface design:
Function or class accepting: list of (raw_book_dict) books, worker count, download callback (callable per book), reporter instance
Returns a result object/dataclass with: downloaded_count, skipped_count, failed_count, failed_books list, skipped_books list
Results grouped by status AND sorted back to original library order (stable sort by original index)
Execution model:
concurrent.futures.ThreadPoolExecutor(max_workers=N) wraps the existing synchronous download_book() call
Each future = one book's full download pipeline (API calls -> streaming -> history write)
as_completed() yields results as each finishes; per-future exceptions caught and recorded as failures
Sibling futures continue unaffected when one fails
Key behaviors:
workers=1 submits 1 at a time (semantically identical to sequential for loop)
One failure never blocks other books
Verbose mode output works correctly with temporal overlap (each thread prints its own verbose lines)
Summary counts are accurate even when multiple books complete within the same millisecond
Testable without network or filesystem: accepts a callable download callback, so tests can inject a mock/simulated download
Acceptance criteria
workers=1 produces identical sequential behavior and results as current for-loop
workers=3 submits all books as futures; multiple execute concurrently
One failed future does not cancel or block sibling futures
Results returned with correct counts (downloaded/skipped/failed)
Failed books returned with (book, reason) tuples; skipped books returned as Book objects
Results within each group sorted in original library order (stable sort)
Download callback is called once per book with correct arguments
Reporter start/complete/fail callbacks fire correctly per book
12-15 new tests: sequential parity, concurrent submission, failure isolation, result grouping/ordering, callback wiring, verbose overlap
No network or filesystem required for orchestrator unit tests
Blocked by
#12 (Slice 1: Config workers field - needed for worker count parameter)
#13 (Slice 2: History thread-safety - needed for concurrent history writes)
#15 (Slice 4: API rate limiter - needed to cap API concurrency inside worker threads)
## Parent
#11
## What to build
New `orchestrator.py` module that encapsulates the `ThreadPoolExecutor` lifecycle for parallel book downloads. This is the core parallelism engine -- it replaces the sequential `for` loop in `cli.py:run()` with a thread-pool-based concurrent execution model.
**Interface design:**
- Function or class accepting: list of (raw_book_dict) books, worker count, download callback (callable per book), reporter instance
- Returns a result object/dataclass with: `downloaded_count`, `skipped_count`, `failed_count`, `failed_books` list, `skipped_books` list
- Results grouped by status AND sorted back to original library order (stable sort by original index)
**Execution model:**
- `concurrent.futures.ThreadPoolExecutor(max_workers=N)` wraps the existing synchronous `download_book()` call
- Each future = one book's full download pipeline (API calls -> streaming -> history write)
- `as_completed()` yields results as each finishes; per-future exceptions caught and recorded as failures
- Sibling futures continue unaffected when one fails
**Key behaviors:**
- `workers=1` submits 1 at a time (semantically identical to sequential for loop)
- One failure never blocks other books
- Verbose mode output works correctly with temporal overlap (each thread prints its own verbose lines)
- Summary counts are accurate even when multiple books complete within the same millisecond
- Testable without network or filesystem: accepts a callable download callback, so tests can inject a mock/simulated download
## Acceptance criteria
- [ ] `workers=1` produces identical sequential behavior and results as current for-loop
- [ ] `workers=3` submits all books as futures; multiple execute concurrently
- [ ] One failed future does not cancel or block sibling futures
- [ ] Results returned with correct counts (downloaded/skipped/failed)
- [ ] Failed books returned with (book, reason) tuples; skipped books returned as Book objects
- [ ] Results within each group sorted in original library order (stable sort)
- [ ] Download callback is called once per book with correct arguments
- [ ] Reporter start/complete/fail callbacks fire correctly per book
- [ ] 12-15 new tests: sequential parity, concurrent submission, failure isolation, result grouping/ordering, callback wiring, verbose overlap
- [ ] No network or filesystem required for orchestrator unit tests
## Blocked by
- #12 (Slice 1: Config workers field - needed for worker count parameter)
- #13 (Slice 2: History thread-safety - needed for concurrent history writes)
- #14 (Slice 3: ProgressReporter multi-bar - needed for concurrent progress reporting)
- #15 (Slice 4: API rate limiter - needed to cap API concurrency inside worker threads)
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Parent
#11
What to build
New
orchestrator.pymodule that encapsulates theThreadPoolExecutorlifecycle for parallel book downloads. This is the core parallelism engine -- it replaces the sequentialforloop incli.py:run()with a thread-pool-based concurrent execution model.Interface design:
downloaded_count,skipped_count,failed_count,failed_bookslist,skipped_bookslistExecution model:
concurrent.futures.ThreadPoolExecutor(max_workers=N)wraps the existing synchronousdownload_book()callas_completed()yields results as each finishes; per-future exceptions caught and recorded as failuresKey behaviors:
workers=1submits 1 at a time (semantically identical to sequential for loop)Acceptance criteria
workers=1produces identical sequential behavior and results as current for-loopworkers=3submits all books as futures; multiple execute concurrentlyBlocked by
✅ Issue #16 Complete — Parallel download orchestrator
What was built
Acceptance Criteria: 11/11 ✅
Commits:
e7e6c62,c874eb3