-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Feature: New RQ
class
#1822
base: master
Are you sure you want to change the base?
Feature: New RQ
class
#1822
Conversation
Codecov ReportPatch coverage has no change and project coverage change:
Additional details and impacted files@@ Coverage Diff @@
## master #1822 +/- ##
==========================================
- Coverage 95.06% 92.70% -2.37%
==========================================
Files 51 52 +1
Lines 7895 8096 +201
==========================================
Hits 7505 7505
- Misses 390 591 +201
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
Thanks for the PR! I really like the concept of having a centralized entry point, but I'm wary about jamming all the args and kwargs that rq = RQ(redis_url)
queue = rq.get_queue('default', ..) # accepts all kwargs that queue accepts, minus connection related ones
worker = rq.get_worker('default, ...) # accepts all kwargs that worker accepts, minus connection related ones
all_workers = rq.get_all_workers() I disagree with having something like this: rq = RQ(redis_url)
rq.get_queue_size('default') I think the above is better expressed as: rq = RQ(redis_url)
rq.get_queue('default').size()
# Or
rq = RQ(redis_url)
queue = rq.get_queue('default')
queue.size() The only methods we may consider supporting in the RQ class is the |
As much as I don't really mind having more verbose convenience methods, I agree with you your suggestion makes for a nicer (and more consistent) API, I'll remove those methods. About the I personally think this is a more powerful way of enqueueing jobs (i've been using it in production for a while now), mainly because it allows for a single import to enqueue to multiple queues (and also allows for some nice shortcuts for common tasks like job status, requeue, etc) - so I would favor keeping the |
Agree, I think making enqueueing jobs easer through But having the |
Let me make some changes and we'll get back to this. The goal was never to represent the actual objects, but rather to unify the access (which occasionally may mean having multiple args/kwargs at times). IMHO some tasks shouldn't even be in the objects themselves ( |
One of the things I have noticed when moving a project to RQ is all the arguments needed in various parts of the system. E.g. if you want to change to use a JSON serializer for your jobs, you pass in your serializer to the When I've seen discussion about simplifying this or moving to a centralized object, I envision something along the lines of an I'm not sure if that's where this is headed or I'm not fully understanding the options, but just thought I'd share a pain point I have had and what I imagine would help alleviate it. For example: # File this is some central part of your project.
# e.g. project/config.py
from rq.config import RQDefaultsConfig
class RQConfig(RQDefaultsConfig):
connection = redis_conn
serializer = JSONSerializer
retry = Retry(max=3)
result_ttl = 0 The default for your project is defined in an environment variable, e.g.: export RQ_CONFIG=project.config.RQConfig Since you need to have a defined Redis connection at a minimum, this would be a requirement. Having a order of overrides, would be cool:
Use defaults from config defined by queue = Queue()
queue.enqueue(say_hello) Or override with another config object. from project.config.AltConfig
queue = Queue(config=AltConfig)
queue.enqueue(say_hello) Or override with kwargs, which would pull from the default config class, but override the specific kwargs provided. queue = Queue(connection=other_connection)
queue.enqueue(say_hello, retry=None) |
Definitely, so the rq worker CLI already accepts a rq = RQ(path_to_config_file=)
# or
rq = RQ(config=config)
queue = rq.get_queue() # We can then pass in kwargs if we want to override predefined configs
worker = rq.get_worker() I'm very much in favor of having a centralized RQ object, but prefer a path where we can merge things into master bit by bit so that we can be more thorough and thoughtful in reviewing each PR. |
This introduces a new
RQ
class, which serves a few purposes:No tests yet, will keep as draft for feedback loop.