Skip to content

Conversation

@danfimov
Copy link
Contributor

@danfimov danfimov commented Nov 18, 2025

Context

Currently, it’s not possible to pass a broker instance directly to WorkerArgs when running a worker programmatically via run_worker(WorkerArgs(...)). For example, in the following scenario, the broker is stored as a class field, which prevents using a string path (as required by the CLI): https://yaso.su/hugecock

This patch adds support for passing a broker instance directly as a parameter instead of using its string path.

Copilot AI review requested due to automatic review settings November 18, 2025 10:00
Copilot finished reviewing on behalf of danfimov November 18, 2025 10:04
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for passing an AsyncBroker instance directly to WorkerArgs, enabling programmatic worker execution without requiring a string import path. This is useful when the broker is stored as a class field rather than at module level.

Key changes:

  • Modified the broker field type in WorkerArgs from str to Union[str, AsyncBroker]
  • Added runtime type checking in start_listen() to handle both string paths and broker instances

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
taskiq/cli/worker/args.py Updated type annotation for broker field to accept both string and AsyncBroker instances
taskiq/cli/worker/run.py Added conditional logic to check if broker is already an AsyncBroker instance before attempting to import it

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@s3rius s3rius merged commit d3097bd into taskiq-python:master Nov 22, 2025
39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants