CELERY_ROUTES - how to route by task name

I'm trying to get celery to route tasks based on the name of the task ... basically, I have tasks called "worker.some_name" and "web.some_name", and I use two different queues, respectively, the work site and the website. I would like all work tasks to go into the work queue and vice versa. I currently have a large CELERY_ROUTES dictionary:

CELERY_ROUTES = { "web.some_name": { "queue": "web" }, "web.some_other_name": { "queue": "web" }, etc.... } 

But I would like something more general:

 CELERY_ROUTES = (MyRouter(), ) class MyRouter(object): def route_for_task(self, task, args=None, kwargs=None): if task.split('.')[0] == "worker": return {"queue": "worker"} return {"queue": "web"} 

But this does not seem to work. Any ideas? Thanks.

+4
source share
2 answers

You may have used the "@ app.task" decorator for the task that you defined in the py file.

You can redirect your task with @ app.task (queue = 'queue_name')

+3
source

You must be able to do what you want by changing the type of exchange from direct to topic. This way you can specify tasks as web. * Or a worker. *

You can read here: http://ask.github.com/celery/userguide/routing.html#topic-exchanges

+2
source

All Articles