Reputation: 13723
When I create a function task, I can do the following to specify the queue:
@app.task(name='my_task', queue='my_queue')
def some_task():
return "hey"
Then, I can call this task like this: some_task.delay()
and it would send the task to the my_queue
.
However, if I have a class that inherits from the celery.Task
class, I have to specify the queue every time I call this task:
class MyTask(Task):
def run(self):
return "Hey"
MyTask.apply_async(queue="my_queue")
Is there a way to specify this in the class definition? Something like this:
class MyTask(Task):
queue = 'my_queue'
def run(self):
return "Hey"
I cannot find a way to do it in the documentation. Is it possible?
Upvotes: 5
Views: 1835
Reputation: 13723
Turns out, that was exactly how you would do it:
class MyTask(Task):
queue = 'my_queue'
def run(self):
return "Hey"
Upvotes: 5