refactor(queue): снизить сложность _run_single_worker F(54)→C (#922)#927
Conversation
`CollectionQueue._run_single_worker` was rank F(54): one ~280-line worker loop owning task dequeue, four pre-dispatch guards, kwargs assembly, completion bookkeeping and six exception handlers. Split the cohesive blocks into methods, leaving the loop as guards + pull + delegation: - `_validate_task_pre_dispatch` — the four skip guards (deleted/cancelled/ scheduled/filtered + shutdown); returns the channel to collect or None - `_build_collect_kwargs` — progress callback + signature-gated cancel_event - `_handle_collection_completion` — cancelled-requeue/cancel vs COMPLETED+note - `_handle_collection_exception` — the six failure handlers, dispatched by an isinstance chain that mirrors the original except-clause precedence; returns (keep_known_task_id, stop_after_no_clients) for the finally block radon cc: `_run_single_worker` F(54) → C(17); largest helper C(16). No behavior change — same guard order, same exception precedence, same terminal statuses; the no-exception `_retried_tasks.discard` now runs at the end of the try body (equivalent to the old else clause). Covered by tests/test_collection_queue_db_pull.py (28 passed). Refs #922. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
@claude @codex review. Focus on critical issues: bugs, security vulnerabilities, logical errors, data loss risks, performance problems. Do NOT nitpick style, naming conventions, minor formatting, or subjective preferences — only flag issues that could break functionality or cause real harm in production. |
|
Claude finished @axisrow's task in 6m 53s —— View job Code Review
SummaryReviewed Issue 1 —
|
|
Codex Review: Didn't find any major issues. Keep it up! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Триаж ревью (cycle 1/3)Спасибо @claude @codex. Codex — без замечаний. По находкам Claude: Issue 1 («
|
|
Claude finished @axisrow's task in 34s —— View job Triage Acknowledgement — Cycle 1/3
Issue 1 —
|
#922) Review nitpick: the split moved the queue-item task_done() accounting into two places — the skip paths inside _validate_task_pre_dispatch and the dispatch-path finally block. Add a comment at the call site documenting the invariant (exactly one task_done() per dequeued item) so future maintainers don't add a second. No behavior change. Refs #922. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Summary
Testing
|
Что и зачем
PR-4 из #922.
CollectionQueue._run_single_worker(src/collection_queue.py) была radon F(54) — ~280-строчный воркер-цикл, владеющий dequeue задачи, 4 pre-dispatch guard-ами, сборкой kwargs, обработкой завершения и 6 except-ветками.Извлечённые методы
_validate_task_pre_dispatch_build_collect_kwargs_handle_collection_completion_handle_collection_exceptionisinstanceв порядке исходных except-веток →(keep_known_task_id, stop_after_no_clients)_run_single_workerтеперь цикл «guards + pull + делегирование». radon cc: F(54) → C(17); самый крупный хелпер C(16).Поведение не меняется
_retried_tasks.discardв no-exception пути перенесён в конец тела try — эквивалент старогоelse.logger.exceptionвызывается из обработчика, вызванного внутриexcept Exception—sys.exc_info()активен, traceback логируется как прежде.Проверка
ruff check src/collection_queue.py— cleanpytest -k collection_queue— 28 passed (все 5 типов исключений + generic + completion + guards + pause/resume + delayed requeue)Refs #922. Внешнее поведение без изменений.
🤖 Generated with Claude Code