2012-07-30 22:01:41 +00:00
|
|
|
connfails=0;
|
|
|
|
|
2013-03-14 18:50:44 +00:00
|
|
|
longpollcallbacks = $.Callbacks();
|
|
|
|
|
global webapp redirects, to finish upgrades
When an automatic upgrade completes, or when the user clicks on the upgrade
button in one webapp, but also has it open in another browser window/tab,
we have a problem: The current web server is going to stop running in
minutes, but there is no way to send a redirect to the web browser to the
new url.
To solve this, used long polling, so the webapp is always listening for
urls it should redirect to. This allows globally redirecting every open
webapp. Works great! Tested with 2 web browsers with 2 tabs each.
May be useful for other purposes later too, dunno.
The overhead is 2 http requests per page load in the webapp. Due to yesod's
speed, this does not seem to noticibly delay it. Only 1 of the requests
could possibly block the page load, the other is async.
2013-11-23 18:47:38 +00:00
|
|
|
// Updates a div with a specified id, by polling an url,
|
|
|
|
// which should return a new div, with the same id.
|
|
|
|
function longpoll_div(url, divid, cont, fail) {
|
2012-07-31 00:22:10 +00:00
|
|
|
$.ajax({
|
|
|
|
'url': url,
|
|
|
|
'dataType': 'html',
|
|
|
|
'success': function(data, status, jqxhr) {
|
|
|
|
$('#' + divid).replaceWith(data);
|
2013-03-14 18:50:44 +00:00
|
|
|
longpollcallbacks.fire();
|
2012-07-31 00:22:10 +00:00
|
|
|
connfails=0;
|
|
|
|
cont();
|
|
|
|
},
|
|
|
|
'error': function(jqxhr, msg, e) {
|
|
|
|
connfails=connfails+1;
|
2013-12-09 21:44:45 +00:00
|
|
|
// It's normal to get 1 failure per longpolling
|
|
|
|
// element when navigating away from a page.
|
|
|
|
// So 12 allows up to 4 longpolling elements per
|
|
|
|
// page.
|
|
|
|
if (connfails > 12) {
|
2012-07-31 00:33:23 +00:00
|
|
|
fail();
|
2012-07-30 22:01:41 +00:00
|
|
|
}
|
2012-07-31 00:22:10 +00:00
|
|
|
else {
|
|
|
|
cont();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2012-07-30 22:01:41 +00:00
|
|
|
}
|
global webapp redirects, to finish upgrades
When an automatic upgrade completes, or when the user clicks on the upgrade
button in one webapp, but also has it open in another browser window/tab,
we have a problem: The current web server is going to stop running in
minutes, but there is no way to send a redirect to the web browser to the
new url.
To solve this, used long polling, so the webapp is always listening for
urls it should redirect to. This allows globally redirecting every open
webapp. Works great! Tested with 2 web browsers with 2 tabs each.
May be useful for other purposes later too, dunno.
The overhead is 2 http requests per page load in the webapp. Due to yesod's
speed, this does not seem to noticibly delay it. Only 1 of the requests
could possibly block the page load, the other is async.
2013-11-23 18:47:38 +00:00
|
|
|
|
|
|
|
function longpoll_data(url, cont) {
|
|
|
|
$.ajax({
|
|
|
|
'url': url,
|
|
|
|
'dataType': 'text',
|
|
|
|
'success': function(data, status, jqxhr) {
|
|
|
|
connfails=0;
|
|
|
|
cont(1, data);
|
|
|
|
},
|
|
|
|
'error': function(jqxhr, msg, e) {
|
|
|
|
connfails=connfails+1;
|
|
|
|
cont(0);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|