【问题标题】:django celery chord task errordjango celery chord 任务错误
【发布时间】:2014-04-12 01:13:32
【问题描述】:

在发送完所有任务后尝试使用 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))

【问题讨论】:

    标签: python django celery django-celery


    【解决方案1】:

    Chord 接受两个参数:第一个子任务列表作为组调用,第二个可选参数是子任务,在列表中的整个任务完成后用作回调。

    Example from API referance:

    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

    【讨论】:

      猜你喜欢
      • 2013-03-06
      • 2018-01-02
      • 1970-01-01
      • 1970-01-01
      • 2013-09-17
      • 1970-01-01
      • 2019-11-08
      • 1970-01-01
      • 2011-06-19
      相关资源
      最近更新 更多