Reputation: 431
I have many workers from different server in celery,(the below picture shows)
and many tasks:
@task(name="task1")
def task1():
.......
@task(name="task2")
def task2():
......
I want to run "task1" only on the "[email protected]_website" worker. How should I config?
Upvotes: 1
Views: 5941
Reputation: 11347
you can give you workers different names, assign each worker to read from a specific queue when running, aka:
celery -A tasks -n worker1 -q queue1 --loglevel=info
celery -A tasks -n worker2 -q queue2 --loglevel=info
...
and than add router, for example:
def route_task(name, args, kwargs, options, task=None, **kw):
if name == 'task1':
return 'queue1'
elif name == 'task2':
return 'queue2'
return None
Note, the implementation depends on the celery version you run (i'm using 3.1) - it changed a little in 4. There are even simpler router in the link I've added (in configuration) - check this out.
Good luck
Upvotes: 2