4

I am trying to use celery to improve browser response time where I can. I am dealing with this workflow issue.

  1. User goes to first page, enters data.
  2. View launches a celery task, then response with a second page.
  3. User enters data on the second page.
  4. View responds with a third page, which requires the task started by the page 1 view response to be completed.

So before the view can respond to the request for page 3, it needs to check if the celery task is complete.

My current idea works through this model:

class CeleryTaskmeta(models.Model): # found using python manage.py inspectdb
    task_id = models.CharField(max_length=255, unique=True)
    status = models.CharField(max_length=150)
    result = models.TextField(blank=True)
    date_done = models.DateTimeField()
    traceback = models.TextField(blank=True)
    hidden = models.IntegerField()
    meta = models.TextField(blank=True)

    class Meta:
        db_table = u'celery_taskmeta'

Would it work / is it the best idea to store the celerytaskmeta_id. And then when the user requests page 3, I would start the view with something like:

def SomeView(request):
    result = CeleryTaskmeta(id = celerytaskmeta_id)
    result.get()
    rest of SomeView ...

Thematically, is it poor use of celery to start a lengthy task, do some other stuff, and then continue once the lengthy task is done?

3
  • Why not allow the user to upload all the data once and then run a unified bigger celery task?
    – miki725
    Mar 4, 2013 at 19:45
  • The user would wait even longer. The task has to complete before the final response, but I can start the task early in the process, allowing it a head start, so to speak.
    – Cole
    Mar 4, 2013 at 20:22
  • 1
    One of the main purposes of celery is to execute tasks without blocking regular request cycle. The better thing to do is to start the task in the background and then let the user know that it is being executed. Then once it finishes, the user will be able to see the result. You can also notify user when the task has been completed either by email or some other means.
    – miki725
    Mar 4, 2013 at 21:36

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.