芹菜-无法获取任务结果

时间:2018-06-27 09:08:44

标签: python django celery django-celery celery-task

我将Django ORM / Cache用作芹菜的结果后端。我可以看到在数据库中创建了django_celery_results_taskresult表。任务完成后,结果也被插入到数据库中,该数据库可以从MySQL查看。但是,当我尝试使用AsyncResultdjango manage.py shell中的任务ID访问结果时,出现以下错误。

>>> AsyncResult.get('88e4d870-1a2b-4675-8f7c-1eacb7199bda')
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/root/vms/lib/python3.6/site-packages/celery/result.py", line 199, in get
    if self.ignored:
AttributeError: 'str' object has no attribute 'ignored'
>>> AsyncResult('88e4d870-1a2b-4675-8f7c-1eacb7199bda').get()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/root/vms/lib/python3.6/site-packages/celery/result.py", line 224, in get
    on_message=on_message,
  File "/root/vms/lib/python3.6/site-packages/celery/backends/base.py", line 470, in wait_for_pending
    no_ack=no_ack,
  File "/root/vms/lib/python3.6/site-packages/celery/backends/base.py", line 773, in _is_disabled
    raise NotImplementedError(E_NO_BACKEND.strip())
NotImplementedError: No result backend is configured.
Please see the documentation for more information.

我的celery.py文件是:

from __future__ import absolute_import, unicode_literals
from celery import Celery
import os

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'vms.settings')

app = Celery('vms', broker='redis://localhost', include=['cve.tasks','cpe.tasks'])

app.conf.update(
    result_backend='django-db',
    timezone = 'Asia/Kolkata'
)

if __name__ == '__main__':
    app.start()

我已将django_celery_results包含在settings.py INSTALLED_APPLICATIONS中。

我觉得很奇怪,结果被插入到数据库中却无法检索。

1 个答案:

答案 0 :(得分:2)

您必须导入您的应用才能访问结果。在您的shell中尝试以下代码:

from path.to.celery import app


app.AsyncResult('88e4d870-1a2b-4675-8f7c-1eacb7199bda')