Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Celery doesn't return results

For some reason, whenever I create and run a new Task in Celery there is a problem with returning the results. The first task returns perfectly, but for all subsequent tasks, the result is always pending. I checked the Celery log, and it gets the correct result with no errors, but it just can't return it.

If it helps, I am running rabbitmq as my backend.

like image 285
veered Avatar asked Nov 10 '10 04:11

veered


2 Answers

Well it turns out I just needed to explicitly specify a backend.

Adding:

CELERY_RESULT_BACKEND = "amqp"

to my settings file seemed to fix everything.

like image 65
veered Avatar answered Oct 30 '22 21:10

veered


I am also getting the same issue even if I add 'amqp' backend.

Here is my celery config file:

BROKER_HOST = "localhost"
BROKER_PORT = 5672
BROKER_USER = "guest"
BROKER_PASSWORD = "guest"
BROKER_VHOST = "/"

CELERY_RESULT_BACKEND = "amqp"
CELERY_AMQP_TASK_RESULT_EXPIRES = 18000  # 5 hours.
CELERY_IMPORTS = ("test", )

My shell where first time get is successful and second time its hung. After sometime if I call the method again it works. This pattern keeps repeating.

>>> r = test.add.delay(4, 4)
>>> r.get()
8
>>> r = test.add.delay(4, 4)
>>> r.get()
^C <---------- it was hung here forever, I had to press ^C

>>> r = test.add.delay(4, 4)
>>> r.get()
8
like image 35
harry Avatar answered Oct 30 '22 20:10

harry