How to handle lengthy data-intensive operations in a web app?
Hello,
I have a highly data-intensive application which has to be kick-started from a web page (which could take anywhere between 15-20 mnts even with threads and optimizations). Usually, I prefer having these as cronjobs but this one needs to be under the user's control. I was thinking of submitting the job and sending a response back with some message like "This may take 15-20 minutes. Please check back later to see the status." etc..but I would like to have some sort of notification to the user once it is finished (no mails etc.) instead of the user checking back everytime. Can anybody suggest a good solution for this?
Thanks in advance!
[668 byte] By [
ragh_dra] at [2007-11-26 18:53:17]

# 1
Unfortunately this requirement is not so easy via the web.
HTTP is a PULL technology, not push.
The client may not even be there when the job is completed - you have no way of knowing.
I think the best you can do in this case is to have the page refresh itself every minute or so asking the server "are you done yet?" If the server could give some indication of how much of the job was complete, you could then update the page with that info.
If you REALLY want to go down the path of server notifiying clients, check out Pushlets at www.pushlets.com
Cheers,
evnafets
# 2
[nobr]There's also a Javascript standard function called init() , called on the HTML body tag ,
for example <body onload="init()"> , and the function gets called as soon as the HTML DOM finishes loading.
I've come accross Javascript code that displays a DIV tag that is tall, and displays a message like "Please wait until this page finishes loading" - and as soon as the page finishes loading the DIV tag is hidden, thus revealing the rest of the page, that was at the bottom of the tall div tag.
This will only work for the entire duration of the page, and can't poll the wait with a given frequency. I don't think it can estimate how long it will take for the page to load.
<div class="loading" id="please_wait_loading" >
<span style="font-size:xx-large;font-family:'Comic Sans MS'">Loading your request. Please Wait!</span>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<span style="font-size:large;"><a href="#startcontent" style="text-decoration:underline">skip this screen</a></span><br/>
</div>
<script type="text/javascript">
var ld;
ld = document.getElementById("please_wait_loading").style;
function init()
{
ld.visibility = "hidden";
ld.display = "none";
}
</script>
[/nobr]
# 3
Thanks evnafets. I will try that. I did think about the refresh..it is good for a few minutes..but for pretty long requests I am hesitant to use that. Thanks again..
Thanks for your reply appy77..I had done something similar in one of my earlier applications. As you said, it works well for a single page load and return scenario.