-
Notifications
You must be signed in to change notification settings - Fork 51
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
base: develop
Are you sure you want to change the base?
RQ integration #333
Conversation
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: |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
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.