根据中的文档http://ask.github.com/celery/userguide/routing.html#manual-路由i可以将CCD_ 1参数传递给CCD_。然而,当使用任务集时,我得到
TypeError at /some/path/
apply_async() got an unexpected keyword argument 'queue'
给定TaskSet类中的以下代码,这是不可取的https://github.com/ask/celery/blob/master/celery/task/sets.py#L122
def apply_async(self, connection=None, connect_timeout=None,
publisher=None, taskset_id=None):
"""Apply taskset."""
app = self.app
if app.conf.CELERY_ALWAYS_EAGER:
return self.apply(taskset_id=taskset_id)
with app.default_connection(connection, connect_timeout) as conn:
setid = taskset_id or uuid()
pub = publisher or self.Publisher(connection=conn)
try:
results = self._async_results(setid, pub)
finally:
if not publisher: # created by us.
pub.close()
return app.TaskSetResult(setid, results)
我有一些未定义的任务,需要在某些情况下应用特殊路由,我应该如何处理?不使用任务集?
您可以使用带有选项参数的子任务
>>> from celery.task.sets import TaskSet
>>> from tasks import add
>>>
>>> job = TaskSet(tasks=[add.subtask(args=(i, i),options={'queue':'celery'}) for i in range(10)])
>>> result = job.apply_async()
>>> result.ready()
True
>>> job
[tasks.add(0, 0), tasks.add(1, 1), tasks.add(2, 2), tasks.add(3, 3), tasks.add(4, 4), tasks.add(5, 5), tasks.add(6, 6), tasks.add(7, 7), tasks.add(8, 8), tasks.add(9, 9)]
>>>