Added code to automatically switch to high latency mode when polling keeps timing out closes #46

pull/73/head
jonsowman 2010-06-20 16:47:31 +01:00
rodzic 05d3768f35
commit 1097193c5b
2 zmienionych plików z 15 dodań i 7 usunięć

Wyświetl plik

@ -45,9 +45,14 @@ var land_img = "images/target-8-sm.png";
var burst_img = "images/pop-marker.png"; var burst_img = "images/pop-marker.png";
var clickListener; var clickListener;
var clickMarker; var clickMarker;
// polling progress parameters
var ajaxTimeout = 500; var ajaxTimeout = 500;
var maxAjaxTimeout = 2000; var maxAjaxTimeout = 2000;
var deltaAjaxTimeout = 500; var deltaAjaxTimeout = 500;
var stdPeriod = 2000; // standard
var hlPeriod = 10000; // high latency
var hlTimeout = 5000; // high latency
</script> </script>
</head> </head>

Wyświetl plik

@ -147,7 +147,7 @@ function handlePred(pred_uuid) {
// disable user control of the map canvas // disable user control of the map canvas
$("#map_canvas").fadeTo(1000, 0.2); $("#map_canvas").fadeTo(1000, 0.2);
// ajax to poll for progress // ajax to poll for progress
ajaxEventHandle = setInterval("getJSONProgress('"+pred_uuid+"')", 2000); ajaxEventHandle = setInterval("getJSONProgress('"+pred_uuid+"')", stdPeriod);
} }
function getCSV(pred_uuid) { function getCSV(pred_uuid) {
@ -183,12 +183,15 @@ function getJSONProgress(pred_uuid) {
appendDebug("Increasing AJAX timeout from " + ajaxTimeout appendDebug("Increasing AJAX timeout from " + ajaxTimeout
+ "ms to " + newTimeout + "ms"); + "ms to " + newTimeout + "ms");
ajaxTimeout = newTimeout; ajaxTimeout = newTimeout;
} else { } else if ( ajaxTimeout != hlTimeout ) {
// otherwise, throw an error and kill the poller // otherwise, increase poll delay and timeout
clearInterval(ajaxEventHandle);
appendDebug("Reached maximum ajaxTimeout value of " + maxAjaxTimeout); appendDebug("Reached maximum ajaxTimeout value of " + maxAjaxTimeout);
throwError("Tried increasing the AJAX polling timeout to "+maxAjaxTimeout clearInterval(ajaxEventHandle);
+"ms but the request still timed out."); appendDebug("Switching to high latency mode");
appendDebug("Setting polling interval to "+hlPeriod+"ms");
appendDebug("Setting progress JSON timeout to "+hlTimeout+"ms");
ajaxTimeout = hlTimeout;
ajaxEventHandle = setInterval("getJSONProgress('"+pred_uuid+"')", hlPeriod);
} }
} }
}, },
@ -221,7 +224,7 @@ function processProgress(progress) {
if ( progress['pred_complete'] == true ) { // pred has finished if ( progress['pred_complete'] == true ) { // pred has finished
$("#prediction_status").html("Prediction finished."); $("#prediction_status").html("Prediction finished.");
appendDebug("Server says: the predictor finished running."); appendDebug("Server says: the predictor finished running.");
appendDebug("Attemping to retrieve flight path from server"); appendDebug("Attempting to retrieve flight path from server");
// reset the GUI // reset the GUI
resetGUI(); resetGUI();
// stop polling for JSON // stop polling for JSON