How to store the result of a delay-call using celery in a django view?
I`ve followed the guidelines in 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 impor开发者_开发技巧t task
@task()
def add(x, y):
time.sleep(10)
return x + y
But if my add-method takes a long time to respond, how can I store the result-object I got when calling add.delay(1,2) and use it to check the progress/success/result using get later?
You only need the task-id:
result = add.delay(2, 2)
result.task_id
With this you can poll the status of the task (using e.g. AJAX) Django-celery comes with a view that returns results and status in JSON: http://celeryq.org/docs/django-celery/reference/djcelery.views.html
精彩评论