在发送完所有任务后,尝试使用chord发送任务时出错。
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Users/wenzhixue/projects/workspace/fallfor_core/twitter/tasks.py", line 13, in bulk_change_bio
chord([change_bio_task.delay(account,'http://fallfor.com') for account in account_list ])(shutdown.s(c))
File "/Library/Python/2.7/site-packages/celery/canvas.py", line 470, in __call__
_chord = self.type
File "/Library/Python/2.7/site-packages/celery/canvas.py", line 467, in type
return self._type or self.tasks[0].type.app.tasks['celery.chord']
AttributeError: 'AsyncResult' object has no attribute 'type'
-
@task()
def shutdown(ec2):
print "shutting down!!!!"
time.sleep(300)
return True
c = Ec2()
account_list = Account.objects.all()
chord([change_bio_task.delay() for account in account_list ])(shutdown.s(c))
Chord接受两个参数:第一个是作为组调用的子任务列表,第二个是可选的,是在列表中的所有任务完成后用作回调的子任务。
API参考文献示例:
res = chord([add.s(2, 2), add.s(4, 4)])(sum_task.s())
在代码中,您传递的是AsyncResults的第一个参数列表,而不是子任务。这应该是正确的:
chord([change_bio_task.s() for account in account_list ])(shutdown.si(c))
看看我把shutdown.s(c)
改成了shutdown.si(c)
,它是不可变的,并且忽略了返回的完成change_bio_task
的结果。