Celery 结果后端。DisabledBackend 对象没有属性 _get_task_meta_for
我已经配置好了celery和后端:
cleryapp = Celery(
'tasks_app', brocker='amqp://guest@localhost//',
backend='db+postgresql://guest@localhost:5432'
)
当我启动工作进程时,'results'看起来是禁用的,但我在这里看到的另一个问题中提到这不是问题所在。
数据库正确接收到了所有数据,但是
result = AsyncResult(task_id)
抛出了
AttributeError: 'DisabledBackend' object has no attribute '_get_task_meta_for'
6 个回答
0
试着在你的 AyscResult
脚本中也导入 task
,这样可以让 celery 知道后端的设置。我之前也遇到过类似的问题(AttributeError: 'DisabledBackend' object has no attribute '_get_task_meta_for'
),虽然后端配置得很好,但这个方法对我帮助很大。
from <your celery app> import <tasks> # add this one
from celery.result AsyncResult
result = AsyncResult(task_id)
print(result.state) # check if it worked or not, it should
0
就像它所说的celery,你需要指定后端的值,像这样:app = Celery("tasks", broker='mongodb://localhost:27017/test',backend='mongodb://localhost:27017/test1')
4
你可以试试:
from celery import result, Celery
app = Celery(backend='redis://localhost:6379/0')
res = result.AsyncResult(id='7037247e-f528-43ba-bce5-ee0e30704c58', app=app)
print(res.info)
8
试试用这个,任务是你函数的名字:
result = task.AsyncResult(task_id)
32
我找到了一种更方便的方法来实现这个。
result = celery.AsyncResult(task_id)
celery
是你应用程序中的 Celery 实例,而不是 celery 模块。