Django和芹菜 - 检查是否准备就绪时,关键错误



我想检查我的任务组是否准备就绪。如果我在芹菜任务中执行此操作,则可以正常工作:

from time import sleep
from celery import task, group
from celery.result import GroupResult
@task
def a():
    sleep(10)

@task
def b():
    c = group(a.si())()
    c.save()
    saved_result = GroupResult.restore(c.id)
    print saved_result.ready()

b.apply_async()

但是,它在我的django视图中不起作用。

task_result = GroupResult.restore(my_hash)
print type(task_result)
if task_result.ready(): # this throws an error
     print 'ready!'

错误:

    if task_result.ready():
  File "/home/kam/project1_env/local/lib/python2.7/site-packages/celery/result.py", line 259, in ready
    return self.state in self.backend.READY_STATES
  File "/home/kam/project1_env/local/lib/python2.7/site-packages/celery/result.py", line 396, in state
    return self._get_task_meta()['status']
  File "/home/kam/project1_env/local/lib/python2.7/site-packages/celery/result.py", line 341, in _get_task_meta
    return self._maybe_set_cache(self.backend.get_task_meta(self.id))
  File "/home/kam/project1_env/local/lib/python2.7/site-packages/celery/result.py", line 332, in _maybe_set_cache
    state = meta['status']
KeyError: 'status'

当我在芹菜击败任务中称呼它时,它会引起错误。

我将Redis用作后端。我的芹菜设置:

BROKER_URL = 'redis://127.0.0.1:6379/1'
CELERY_RESULT_BACKEND = 'redis://127.0.0.1:6379/1'
CELERY_ACCEPT_CONTENT = ['json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'

已解决。我有一个没有任务的小组。

相关内容

  • 没有找到相关文章

最新更新