airfang
airfang

Reputation: 1238

django-celery: No result backend configured

I am trying to use django-celery in my project

In settings.py I have

CELERY_RESULT_BACKEND = "amqp"

The server started fine with

python manage.py celeryd --setting=settings

But if I want to access a result from a delayed task, I get the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\celery\result.py", line 108, in ready
    return self.status in self.backend.READY_STATES
  File "C:\Python27\lib\site-packages\celery\result.py", line 196, in status
    return self.state
  File "C:\Python27\lib\site-packages\celery\result.py", line 191, in state
    return self.backend.get_status(self.task_id)
  File "C:\Python27\lib\site-packages\celery\backends\base.py", line 404, in _is
_disabled
    raise NotImplementedError("No result backend configured.  "
NotImplementedError: No result backend configured.  Please see the documentation
 for more information.

It is very strange because when I just run celeryd (with the same celery settings), it works just fine. Has anyone encountered this problem before?

Thanks in advance!

Upvotes: 20

Views: 24266

Answers (8)

kta
kta

Reputation: 20110

In my case there were issues during celery initialisation. Celery was not automatically reading django setting data.

if 'APP_ENV' in os.environ and os.environ['APP_ENV'] == 'dev': 
  os.environ.setdefault("DJANGO_SETTINGS_MODULE", "master.settings.local")

app = Celery('master', namespace='CELERY')

However, I changed to following to feed setting configuration to Celery worker.

app = Celery('master')

if 'APP_ENV' in os.environ and os.environ['APP_ENV'] == 'dev':
  app.config_from_object("master.settings.local", namespace='CELERY')
 

Besides, my Django setting now looks like this

CELERY_BROKER_URL = os.getenv('CELERY_BROKER_URL')
CELERY_BAKEND_URL = os.getenv('CELERY_BAKEND_URL')
CELERY_RESULT_BACKEND=os.getenv('CELERY_BAKEND_URL')
CELERY_TIMEZONE = "Australia/Tasmania"
CELERY_TASK_TRACK_STARTED = True
CELERY_TASK_TIME_LIMIT = 30 * 60
CELERY_TASK_RESULT_EXPIRES = 18000 # 5 hours

Notice, I added CELERY_RESULT_BACKEND. Hope this will save someone else's time.

Upvotes: 0

Inaam Ilahi
Inaam Ilahi

Reputation: 125

For users encountering this issue in 2023. If you are using Celery version 5.0 or greater, set CELERY_RESULT_BACKEND = "rpc://" in settings. If you are initializing the celery app, use the below code:

Celery('your_project_name',
     broker = 'amqp://guest:guest@localhost:5672//',
     backend='rpc://',
     include=['proj.tasks'])

Upvotes: 1

Pablo Guerrero
Pablo Guerrero

Reputation: 1054

In my case, the problem was that I was passing the CELERY_RESULT_BACKEND argument to the celery constructor:

Celery('proj',
         broker = 'amqp://guest:guest@localhost:5672//',
         CELERY_RESULT_BACKEND='amqp://',
         include=['proj.tasks'])

The solution was to use the backend argument instead:

Celery('proj',
         broker = 'amqp://guest:guest@localhost:5672//',
         backend='amqp://',
         include=['proj.tasks'])

Upvotes: 3

Nitin Bhojwani
Nitin Bhojwani

Reputation: 712

See AMQP BACKEND SETTINGS for better understanding

Note The AMQP backend requires RabbitMQ 1.1.0 or higher to automatically expire results. If you are running an older version of RabbitMQ you should disable result expiration like this: CELERY_TASK_RESULT_EXPIRES = None

Try adding the below line to your settings.py:

CELERY_TASK_RESULT_EXPIRES = 18000 # 5 hours

Upvotes: 0

Oleg Kirichenko
Oleg Kirichenko

Reputation: 21

For those who are in a desperate search for a solution like I was.

Put this line at the end of the settings.py script:

djcelery.setup_loader()

Looks like django-celery is not going to consider it's own settings without a strict order.

Upvotes: 2

psekar
psekar

Reputation: 89

I had the same problem while getting the result back from the celery task although the celery task was executed ( console logs). What i found was, i had the same setting CELERY_RESULT_BACKEND = "redis" in django settings.py but i had also instantiated celery in the tasks.py

celery = Celery('tasks', broker='redis://localhost') - which i suppose overrides the settings.py property and hence it was not configuring the backend server for my celery instance which is used to store the results.

i removed this and let django get celery get properties from settings.py and the sample code worked for me.

Upvotes: 7

per06a
per06a

Reputation: 51

If you're just running the samples from http://www.celeryproject.org/tutorials/first-steps-with-celery/, you need to run the console via manage.py:

% python manage.py shell

Upvotes: 4

airfang
airfang

Reputation: 1238

Some how the console has to have django environment set up in order to pick up the settings. For example, in PyCharm you can run django console, in which everything works as expected.

Upvotes: 0

Related Questions