Celery with RabbitMQ: AttributeError: 'DisabledBackend' object has no attribute '_get_task_meta_for'

PythonCelery

Python Problem Overview


I'm running the First Steps with 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:

[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?

Python Solutions


Solution 1 - Python

Just keep reading tutorial. It will be explained in Keep Results chapter.

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.

Solution 2 - Python

I suggest having a look at: 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.

Solution 3 - Python

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:

app = Celery('tasks', backend='rpc://', broker='amqp://guest@localhost//')

When I run python from the command line I get:

$ 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.

Solution 4 - Python

What is not clear by the tutorial is that the tasks.py module needs to be edited so that you change the line:

app = Celery('tasks', broker='pyamqp://guest@localhost//')

to include the RPC result backend:

app = Celery('tasks', backend='rpc://', broker='pyamqp://')

Once done, Ctrl + C the celery worker process and restart it:

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.

Solution 5 - Python

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'

note: this is if you are using django-celery as the backend for storing the messages in the queue.

Solution 6 - Python

Celery rely both on a backend AND a broker. This solved it for me using only Redis:

app = Celery("tasks", backend='redis://localhost',broker="redis://localhost")

Remember to restart worker in your terminal after changing the config

Solution 7 - Python

My case was simple - I used interactive Python console and Python cached imported module. I killed console and started it again - everything works as it should.

import celery


app = celery.Celery('tasks', broker='redis://localhost:6379',
                    backend='mongodb://localhost:27017/celery_tasks')

@app.task
def add(x, y):
    return x + y

In Python console.

>>> from tasks import add
>>> result = add.delay(4, 4)
>>> result.ready()
True

Solution 8 - Python

I had the same issue, what resolved it for me was to import the celery file (celery.py) in the init function of you're app with something like:

from .celery import CELERY_APP as celery_app

__all__ = ('celery_app',)

if you use a celery.py file as described here

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionCasebashView Question on Stackoverflow
Solution 1 - PythondaniulaView Answer on Stackoverflow
Solution 2 - PythonTorokLevView Answer on Stackoverflow
Solution 3 - PythonDiederikView Answer on Stackoverflow
Solution 4 - PythonChris FooteView Answer on Stackoverflow
Solution 5 - PythonCarlisleView Answer on Stackoverflow
Solution 6 - PythonPunnerudView Answer on Stackoverflow
Solution 7 - PythonOmonyView Answer on Stackoverflow
Solution 8 - PythonfsulserView Answer on Stackoverflow