4

I am using Django with Celery + RabbitMQ to create video conversion tasks of videos being uploaded by the users. Now I know how to query celery to get the status. My question is where to save the task_id associated with each task, should I save it in models or in django's cache?

I know that similar questions have been asked in the past e.g. this stackoverflow question but there has been no definitive answer yet. I know the answer to this varies per developer's preferences but if someone can educate on pros/cons of different approaches, that will be great.

Just to re-iterate I will use the task_id to fire AJAX queries every so often from the front-end to know if the video conversion is completed or not.

Community
  • 1
  • 1
Chantz
  • 5,883
  • 10
  • 56
  • 79

2 Answers2

8

If you have django_celery installed, you can query views like task_status or is_task_successful that come in the djcelery.views package. They return a JSON dictionary so you can handle them with JavaScript.

Camilo Díaz Repka
  • 4,805
  • 5
  • 43
  • 68
  • 1
    I think my problem was more related to "how to track which task was created for which model.object?" So e.g. I can goto the djcelery.views but I wouldn't know which "task" relates to which "task_creator". to get around this I went with @crodjer answer above. – Chantz Feb 17 '11 at 16:30
4

Refer to my answer on your linked question: Test if a celery task is still being processed

So after setting the celery_task field, you could easily define a ajax view which would return the task status in a required format.

Community
  • 1
  • 1
crodjer
  • 13,384
  • 9
  • 38
  • 52
  • Yup that sounds pretty good. Just out of curiosity, would saving a "celery_task" to the model be good design considering we will be using the task only once, just when we will do video conversion & not anytime later. I mean we will be using that information in our model only about once or twice. But I guess this is the only sane solution? – Chantz Jan 31 '11 at 03:53
  • Also further can I use JSON instead of PickledObjectField()? Also you meant django-picklefield's implementation of PickledObjectField. Right? – Chantz Jan 31 '11 at 04:10
  • actually I implemented it for distributed computing in my coding contest project. So in that case the results, compilation status for codes were saved in tasks, hence it was required for future lookup. How would you monitor the task when you use JSON. I mean you need to save the celery task result object in the field to have the methods for checking status available for future. – crodjer Jan 31 '11 at 04:27
  • Actually I just need the task_id which I can obtain the moment I create the task doing so, http://dpaste.com/371454/ And I can always get the status doing so, http://dpaste.com/370419/ – Chantz Jan 31 '11 at 15:21