Use case:
class MyTask(Task):
queue = 'default_queue'
def run(self):
# do work
Normally I would run the following which would use the 'default_queue' specified.
MyTask.delay()
What I need to do is something like:
if hours_since_last_login > 24:
MyTask.delay() # using the queue 'high_priority_queue'
else:
MyTask.delay() # using the 'default_queue'
I know I can subclass MyTask to override the queue
property, but is there a way to define it at runtime?
Is this the following the correct way to do it?
task = MyTask()
task.queue = 'high_priority_queue'
task.delay()
The simplest way to do routing is to use the task_create_missing_queues setting (on by default). With this setting on, a named queue that's not already defined in task_queues will be created automatically. This makes it easy to perform simple routing tasks.
Celery is an open source asynchronous task queue or job queue which is based on distributed message passing. While it supports scheduling, its focus is on operations in real time. Celery. Stable release. 5.2.3 / December 29, 2021.
From askol on IRC:
MyTask.apply_async(args=[], kwargs={}, queue='high_priority_queue')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With