How to save result of celery delays in django view?

I followed the recommendations at http://celeryq.org/docs/django-celery/getting-started/first-steps-with-django.html and created a view that calls my test method in tasks.py:

import time from celery.decorators import task @task() def add(x, y): time.sleep(10) return x + y 

But if my add-method takes a long time to answer, how can I save the result object that I got when I called add.delay (1,2) and use it to check progress / success / result using get later

+6
django view celery
source share
1 answer

You only need the task identifier:

 result = add.delay(2, 2) result.task_id 

With this, you can query the status of a task (using, for example, AJAX) Django-celery comes with a view that returns results and status in JSON: http://celeryq.org/docs/django-celery/reference/djcelery.views. html

+4
source share

All Articles