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