Slice 3: ProgressReporter multi-bar support #14

Closed
opened 2026-06-03 16:46:54 +02:00 by AlexKucera · 1 comment
AlexKucera commented 2026-06-03 16:46:54 +02:00 (Migrated from github.com)

Parent

#11

What to build

Upgrade both ProgressReporter (TTY/Rich) and PlainTextReporter (cron) from single-book singleton state (_current_task, _current_book) to a per-book identity mapping ({task_id: book} / {book_id: task_id}). This enables N simultaneous progress bars or interleaved log lines when multiple books download concurrently.

ProgressReporter changes:

  • Replace _current_task / _current_book with _tasks: dict[object, int] (book -> task_id) and _books: dict[int, object] (task_id -> book)
  • start_download(book) -> create Rich task, store bidirectional mapping, return task_id
  • update(completed, *, total, task_id=None) -> look up task from caller-provided identity; fall back to "most recently started" if no task_id for backward compat
  • complete(book) -> look up task by book, mark complete, remove from mappings, print status line
  • fail(book, reason) -> look up task by book, stop task, remove from mappings, print failure line
  • Rich Progress natively supports multiple concurrent tasks -- no library changes needed

PlainTextReporter changes:

  • Same dict pattern but simpler: just thread-safe log line output
  • _print() already writes atomically per line (single write() + flush())
  • No bar management needed -- only start_download/complete/fail produce output

Thread safety: Both reporters use per-book identity lookup. No shared mutable state is mutated concurrently (dict mutations happen in start_download which is called before worker threads begin competing).

Acceptance criteria

  • ProgressReporter.start_download("Book A") then start_download("Book B") shows two simultaneous Rich progress bars
  • update(task_id=X) updates the correct bar (not always the last one)
  • complete("Book A") removes only Book A's bar; Book B's bar continues
  • fail("Book B") removes only Book B's bar; prints failure line
  • summary() fires after all tasks done, stops progress cleanly
  • PlainTextReporter produces correctly interleaved start/complete/fail lines for concurrent books
  • 6-8 new tests covering multi-bar lifecycle, correct bar removal, plain text interleaving
  • All existing progress tests pass (backward-compatible fallback)

Blocked by

None - can start immediately

## Parent #11 ## What to build Upgrade both `ProgressReporter` (TTY/Rich) and `PlainTextReporter` (cron) from single-book singleton state (`_current_task`, `_current_book`) to a per-book identity mapping (`{task_id: book}` / `{book_id: task_id}`). This enables N simultaneous progress bars or interleaved log lines when multiple books download concurrently. **ProgressReporter changes:** - Replace `_current_task` / `_current_book` with `_tasks: dict[object, int]` (book -> task_id) and `_books: dict[int, object]` (task_id -> book) - `start_download(book)` -> create Rich task, store bidirectional mapping, return task_id - `update(completed, *, total, task_id=None)` -> look up task from caller-provided identity; fall back to "most recently started" if no task_id for backward compat - `complete(book)` -> look up task by book, mark complete, remove from mappings, print status line - `fail(book, reason)` -> look up task by book, stop task, remove from mappings, print failure line - Rich `Progress` natively supports multiple concurrent tasks -- no library changes needed **PlainTextReporter changes:** - Same dict pattern but simpler: just thread-safe log line output - `_print()` already writes atomically per line (single `write()` + `flush()`) - No bar management needed -- only `start_download`/`complete`/`fail` produce output **Thread safety:** Both reporters use per-book identity lookup. No shared mutable state is mutated concurrently (dict mutations happen in `start_download` which is called before worker threads begin competing). ## Acceptance criteria - [ ] `ProgressReporter.start_download("Book A")` then `start_download("Book B")` shows two simultaneous Rich progress bars - [ ] `update(task_id=X)` updates the correct bar (not always the last one) - [ ] `complete("Book A")` removes only Book A's bar; Book B's bar continues - [ ] `fail("Book B")` removes only Book B's bar; prints failure line - [ ] `summary()` fires after all tasks done, stops progress cleanly - [ ] `PlainTextReporter` produces correctly interleaved start/complete/fail lines for concurrent books - [ ] 6-8 new tests covering multi-bar lifecycle, correct bar removal, plain text interleaving - [ ] All existing progress tests pass (backward-compatible fallback) ## Blocked by None - can start immediately
AlexKucera commented 2026-06-03 17:30:27 +02:00 (Migrated from github.com)

✅ Complete via commit 35cd34b — per-book identity mapping for concurrent progress bars (7/7 AC, 10 new tests, 194 total passing)

✅ Complete via commit `35cd34b` — per-book identity mapping for concurrent progress bars (7/7 AC, 10 new tests, 194 total passing)
Sign in to join this conversation.