0
自分のタスクグループが準備ができているかどうかを確認したい。私はセロリのタスク内でそれを行う場合は、それが正常に動作します:DjangoとCelery - GroupResultの準備ができているかどうかを確認するときのキーエラー
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'