Skip to content

refactor(decorators): move _wrap_task into mixin#148

Merged
pratyush618 merged 1 commit into
masterfrom
refactor/extract-wrap-task
May 8, 2026
Merged

refactor(decorators): move _wrap_task into mixin#148
pratyush618 merged 1 commit into
masterfrom
refactor/extract-wrap-task

Conversation

@pratyush618
Copy link
Copy Markdown
Collaborator

Summary

Moves _wrap_task (the closure that wraps task functions with hooks, middleware, proxies, and resource injection) and _get_middleware_chain from Queue in py_src/taskito/app.py to QueueDecoratorMixin in py_src/taskito/mixins/decorators.py.

_wrap_task was already invoked from QueueDecoratorMixin.task() (the @queue.task decorator); co-locating it removes the # type: ignore[attr-defined] on that call site and brings app.py from 691 → 577 LOC. The mixin grows by ~140 lines.

The audit recommended mixins/lifecycle.py, but that mixin owns worker startup, banner, and heartbeat — orthogonal concerns. The decorator mixin is the actual consumer of _wrap_task, so it belongs there.

Addresses recommendation 8 from the 2026-05-08 audit (.claude/reports/audit-2026-05-08.md).

Implementation notes

  • _emit_event is provided by QueueEventsMixin. The decorator mixin gets a class-level callable annotation (_emit_event: Callable[..., None]) — not a stub method — so type checkers see it without overriding the real implementation through MRO. (An earlier draft used a stub method that silently shadowed the events-mixin implementation and broke workflow event delivery; the regression was caught locally.)
  • The full set of Queue attributes that _wrap_task reads (_interceptor, _proxy_registry, _proxy_metrics, _resource_runtime, _test_mode_active, _recipe_signing_key, _max_reconstruction_timeout, _global_middleware) are now declared as class-level annotations on QueueDecoratorMixin.
  • app.py drops six imports that were only used by _wrap_task (functools, run_maybe_async, _clear_context, current_job, reconstruct_args, cleanup_proxies, reconstruct_proxies). Those move to the decorator mixin.

Test plan

  • cargo test --workspace — clean.
  • cargo clippy --workspace — clean.
  • uv run python -m pytest tests/python/ — 506 passed, 9 skipped (no regressions).
  • uv run mypy py_src/taskito/ tests/python/ --no-incremental — clean.
  • uv run ruff check py_src/ tests/ — clean.

@github-actions github-actions Bot added the python label May 8, 2026
@pratyush618 pratyush618 merged commit 73cc02d into master May 8, 2026
19 checks passed
@pratyush618 pratyush618 deleted the refactor/extract-wrap-task branch May 8, 2026 04:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant