Comments (3)
I accomplished a behavior similar to this by queuing the second job at the end of the first job. i.e. I run a script as my first job and at the end of the script I added some logic to enqueue a new job depending on the outputs that were just created.
from rq.
I ended up doing something similar to that, where I read the contents of the queue to see what jobs are running or scheduled, then add the new job to depend_on the last job in that list.
I was hoping to find a more elegant solution, though.
My code looks something like this:
queue = 'the selected queue'
job_id = 'some string'
q = Queue(queue, connection=redis)
from rq.registry import StartedJobRegistry, DeferredJobRegistry
running_jobs = StartedJobRegistry(queue, connection=redis).get_job_ids()
deferred_jobs = DeferredJobRegistry(queue, connection=redis).get_job_ids()
with app.app_context():
if len(deferred_jobs) > 0:
last_job = deferred_jobs[-1]
job = q.enqueue(f=args[0], job_timeout='1h', job_id=job_id, args=args[1:], depends_on=last_job)
elif len(running_jobs) > 0:
last_job = running_jobs[-1]
job = q.enqueue(f=args[0], job_timeout='1h', job_id=job_id, args=args[1:], depends_on=last_job)
else:
job = q.enqueue(f=args[0], job_timeout='1h', job_id=job_id, args=args[1:])
from rq.
It sounds like you're using Queue as individualistic rather than a collection
[q1, q2, q3] is analogous to [high-prioritiy-queue, medium-priority-queue, low-priority-queue] within the queue namespace redis:queue:
Which is why you're seeing the behavior regarding job/function ordering
Given your use case, I would take a look at Queue(redis_queue_namespace_prefix: str)
. This would allow you to create a queue namespace per customer to allow for non-overlapping Jobs.
https://github.com/rq/rq/blob/a8209391fffe3bad195264e6ed22724e36ae1fb5/rq/queue.py#L69C1-L69C52
customer_foo: 'foo'
customer_bar: 'bar'
foo_q = Queue(['q1', 'q2', 'q3'], connection=redis, redis_queue_namespace_prefix=f'redis:queue:{customer_foo}:')
bar_q = Queue(['q1', 'q2', 'q3'], connection=redis, redis_queue_namespace_prefix=f'redis:queue:{customer_bar}:')
foo_q.enqueue(my_func_1)
bar_q.enqueue(my_func_1)
foo_q.enqueue(my_func_2)
Depending how you manage your workers, that might not be feasible.
Whether or not it is, If you aren't using dependencies already, I would recommend it.
Line 1537 in a820939
There seems to be some code that allows for dependencies to be
enqueued_at_front
that could potentially resolve the problemLine 67 in a820939
Good luck!
from rq.
Related Issues (20)
- Jobs being lost when killing workers HOT 2
- Use RedisCluster as connection argument for rq worker (redis 5.0.1, rq 1.15.1) HOT 17
- Make registry cleaning lock expiry configurable HOT 2
- Programmatically create more workers at run-time by using Django_rq
- Seg fault 11 on setprocname HOT 1
- execute code with workhorse PID after the workhorse exits HOT 1
- ValueError: Invalid attribute name for job callback HOT 1
- Job.get_status() does not always return JobStatus Enum
- database connection issues when using rq with flask-sqlalchemy HOT 1
- Work-horse termination HOT 1
- DeprecationWarning: datetime.datetime.utcnow() HOT 1
- Rq Worker.all cannot find worker
- Are two connections per worker needed? HOT 1
- keys of command in MULTI calls must be in same slot HOT 3
- How to configure worker-pool via configuration file ? HOT 1
- multiple __init__ , version 1.16 HOT 1
- RQ Tasks Failed Upon Importing Native MacOS modules HOT 3
- 1.16.1: pytest fails in `tests/test_sentry.py::TestSentry::test_failure_capture` and pytest warnings HOT 7
- Jobs wrongly moved to failed registry (stuck in intermediate queue) HOT 9
- Replace Redis with open source alternative? HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rq.