Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RQ integration #333

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open

RQ integration #333

wants to merge 6 commits into from

Conversation

prepin
Copy link

@prepin prepin commented Jan 8, 2025

I've added integration for RQ.

Due to the way RQ is implemented, injecting dependencies with the @inject decorator is not possible, as RQ throws the task function out of the original context and completely ignores any decorators applied.

So, the way to go is to subclass the Worker and perform injection at the subclass level. The implementation is a little bit strange, as I am here manually rebuilding kwargs dictionary. But it works.

mock_call = Mock(name="mock_perform_job", return_value=True)
mock_queue = Mock(spec=Queue)

with patch.object(Worker, "perform_job", mock_call) as mock_perform_job:
Copy link
Member

Choose a reason for hiding this comment

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

do we really need patch here?

Copy link
Author

Choose a reason for hiding this comment

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

Actually, we don't. Removed patching.

container = make_container(provider)
queues = ["default"]
conn = Redis()
worker = DishkaWorker(container=container, queues=queues, connection=conn)
Copy link
Member

Choose a reason for hiding this comment

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

Is it the only way to setup integration? How like is it that user has their own custom worker class?

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