Python Celery with RabbitMQ: AttributeError: 'DisabledBackend' 对象没有属性 '_get_task_meta_for'
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23215311/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Celery with RabbitMQ: AttributeError: 'DisabledBackend' object has no attribute '_get_task_meta_for'
提问by Casebash
I'm running the First Steps with Celery Tutorial.
我正在运行Celery Tutorial 的第一步。
We define the following task:
我们定义了以下任务:
from celery import Celery
app = Celery('tasks', broker='amqp://guest@localhost//')
@app.task
def add(x, y):
return x + y
Then call it:
然后调用它:
>>> from tasks import add
>>> add.delay(4, 4)
But I get the following error:
但我收到以下错误:
AttributeError: 'DisabledBackend' object has no attribute '_get_task_meta_for'
I'm running both the celery worker and the rabbit-mq server. Rather strangely, celery worker reports the task as succeeding:
我正在运行 celery worker 和 rabbit-mq 服务器。奇怪的是,celery worker 报告任务成功:
[2014-04-22 19:12:03,608: INFO/MainProcess] Task test_celery.add[168c7d96-e41a-41c9-80f5-50b24dcaff73] succeeded in 0.000435483998444s: 19
Why isn't this working?
为什么这不起作用?
采纳答案by daniula
Just keep reading tutorial. It will be explained in Keep Resultschapter.
继续阅读教程。这将在保持结果章节中解释。
To start Celery you need to provide just broker parameter, which is required to send messages about tasks. If you want to retrieve information about state and results returned by finished tasks you need to set backend parameter. You can find full list with description in Configuration docs: CELERY_RESULT_BACKEND.
要启动 Celery,您只需要提供 broker 参数,这是发送有关任务的消息所必需的。如果要检索有关已完成任务返回的状态和结果的信息,则需要设置后端参数。您可以在配置文档中找到带有描述的完整列表: CELERY_RESULT_BACKEND。
回答by TorokLev
I suggest having a look at: http://www.cnblogs.com/fangwenyu/p/3625830.html
我建议看看:http: //www.cnblogs.com/fangwenyu/p/3625830.html
There you will see that instead of
在那里你会看到,而不是
app = Celery('tasks', broker='amqp://guest@localhost//')
you should be writing
你应该写
app = Celery('tasks', backend='amqp', broker='amqp://guest@localhost//')
This is it.
就是这个。
回答by Diederik
In case anyone made the same easy to make mistake as I did: The tutorial doesn't say so explicitly, but the line
万一有人像我一样容易犯错:教程没有明确说明,但行
app = Celery('tasks', backend='rpc://', broker='amqp://')
is an EDIT of the line in your tasks.py
file. Mine now reads:
是tasks.py
文件中行的编辑。我的现在写着:
app = Celery('tasks', backend='rpc://', broker='amqp://guest@localhost//')
When I run python from the command line I get:
当我从命令行运行 python 时,我得到:
$ python
>>> from tasks import add
>>> result = add.delay(4,50)
>>> result.ready()
>>> False
All tutorials should be easy to follow, even when a little drunk. So far this one doesn't reach that bar.
所有教程都应该很容易理解,即使有点醉。到目前为止,这个还没有达到那个标准。
回答by Carlisle
in your project directory find the settings file.
在您的项目目录中找到设置文件。
then: sudo vim settings.py copy/paste into settings.py: CELERY_RESULT_BACKEND='djcelery.backends.database:DatabaseBackend'
然后:sudo vim settings.py 复制/粘贴到 settings.py: CELERY_RESULT_BACKEND='djcelery.backends.database:DatabaseBackend'
note: this is if you are using django-celery as the backend for storing the messages in the queue.
注意:这是如果您使用 django-celery 作为后端将消息存储在队列中。
回答by Chris Foote
What is not clear by the tutorial is that the tasks.py module needs to be edited so that you change the line:
教程中不清楚的是需要编辑 tasks.py 模块,以便您更改行:
app = Celery('tasks', broker='pyamqp://guest@localhost//')
to include the RPC result backend:
包括 RPC 结果后端:
app = Celery('tasks', backend='rpc://', broker='pyamqp://')
Once done, Ctrl + Cthe celery worker process and restart it:
完成后,Ctrl + C芹菜工人进程并重新启动它:
celery -A tasks worker --loglevel=info
The tutorial is confusing in that we're making the assumption that creation of the app object is done in the client testing session, which it is not.
本教程令人困惑,因为我们假设 app 对象的创建是在客户端测试会话中完成的,但事实并非如此。