I need to display some analytics to the user; however, occasionally these analytics can take a while to crunch (sometimes 2-5 seconds). Instead of waiting on these results, I think I would like to have them updated in a dynamic way on the webpage.
I already have celery implemented in a limited way, but what I would like to do is send some tasks to celery, have the screen render, and once the function is complete, send the return value to the webpage to by udpated.
Once the task is created, should I monitor its status, or once its complete can I just send the json to the webpage directly? some code examples would be helpful.
Thank you.
“Pushing” data is very hard to do with django. It is not supported natively and the solutions are hacky at best.
There are simpler options, the most popular being ajax polling.
the user could set off a request to do analytics.
django queues the process and marks it as processing in storage
every x seconds the user make an ajax call requesting the status of the request.
when the request is finished the storage is updated to reflect this the next poll request made can retrieve the appropriate data.
HTML5 has native support for socket based communication. but django does not support it.
Django Push HTTP Response to users