开发者

Best way to query Celery using AJAX from front-end to know if a created task is completed or not?

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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜