我正在使用Django ORM/Cache作为芹菜的结果后端。我可以看到django_celery_results_taskresult
表中创建了表。任务完成后,结果也会插入到可以从MySQL查看的数据库中。但是当我尝试使用AsyncResult
和任务ID访问结果时django manage.py shell
出现以下错误。
>>> 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
中。
我觉得结果入数据库但无法检索很奇怪。
您必须导入应用程序才能访问结果。在外壳中尝试以下代码:
from path.to.celery import app
app.AsyncResult('88e4d870-1a2b-4675-8f7c-1eacb7199bda')