How to install backend for django-celery. I set CELERY_RESULT_BACKEND, but it is not recognized

I set CELERY_RESULT_BACKEND = "amqp" in celeryconfig.py but I get:

>>> from tasks import add >>> result = add.delay(3,5) >>> result.ready() Traceback (most recent call last): File "<console>", line 1, in <module> File "/djangoprojects/venv/local/lib/python2.7/site-packages/celery/result.py", line 105, in ready return self.state in self.backend.READY_STATES File "/djangoprojects/venv/local/lib/python2.7/site-packages/celery/result.py", line 184, in state return self.backend.get_status(self.task_id) File "/djangoprojects/venv/local/lib/python2.7/site-packages/celery/backends/base.py", line 414, in _is_disabled raise NotImplementedError("No result backend configured. " NotImplementedError: No result backend configured. Please see the documentation for more information. 
+6
source share
2 answers

I just went through it so I can shed light on it. You might think that for all the wonderful documents in which some of them would be more obvious.

I assume that you have both RabbitMQ and it works (it must be running), and that you have dj-celery installed.

After that, all you have to do is include this single line in the settings.py file.

 BROKER_URL = "amqp://guest: guest@localhost :5672//" 

Then you need to run syncdb and run this thing using:

 python manage.py celeryd -E -B --loglevel=info 

-E indicates that you want events to be captured, and -B states that you want celerybeats to function. The former allow you to see something in the admin window, and later to plan. Finally, you need to make sure that you are actually going to capture events and status. Therefore, in another terminal, do the following:

 ./manage.py celerycam 

And finally, finally, you can see the working example presented in the documents. - Again assuming you created task.py that says.

 >>> result = add.delay(4, 4) >>> result.ready() # returns True if the task has finished processing. False >>> result.result # task is not ready, so no return value yet. None >>> result.get() # Waits until the task is done and returns the retval. 8 >>> result.result # direct access to result, doesn't re-raise errors. 8 >>> result.successful() # returns True if the task didn't end in failure. True 

In addition, you can view your status in the admin panel.

Django task manager

Hope this helps! I would add one more thing that helped me. Monitoring the RabbitMQ log file was key, as it helped me determine that django-celery was really talking to RabbitMQ.

+12
source

Do you use django celery?

If so, you need to run the python shell in the django context (or whatever the technical term is).

A type:

 python manage.py shell 

And try your commands from this shell

+1
source

Source: https://habr.com/ru/post/916132/


All Articles