Reputation: 2486
I want the user to be able to click a button to generate a report, show him a generating report animation and then once the report finishes generating, display the word success on the page.
I am thinking of creating a celery task when the generate report button is clicked. What is the best way for me to update the UI once the task is over? Should I constantly be checking via AJAX calls if the task has been completed? Is there a better way or third party notification kind of app in Django that helps with this process?
Thanks!
Edit: I did more research and the only thing I could find is three way data bindings with django-angular
and django-websocket-redis
. Seems like a little bit of an overkill just for this small feature. I guess without web sockets, the only possible way is going to be constantly polling the backend every x seconds to check if the task has completed. Any more ideas?
Upvotes: 5
Views: 1056
Reputation: 64847
Note that polling means you'll be keeping the request and connection open. On web applications with large amount of hits, this will waste a significant amount of resource. However, on smaller websites the open connections may not be such a big deal. Pick a strategy that's easiest to implement now that will allow you to change it later when you actually have performance issues.
Upvotes: 2
Reputation: 1656
Polling is a good and simple solution for this. Avoid adding unnecessary overhead to your site for simple features.
while Result.state == u'PENDING':
#do your stuff
if Result.state == u'SUCCESS':
#Finished
else:
#something wrong
Upvotes: 0