From d21417dd0c2513e01f1c24f5ec1883dd04e0f83f Mon Sep 17 00:00:00 2001 From: jonsowman Date: Sat, 19 Jun 2010 23:35:25 +0100 Subject: [PATCH] Auto adjusting AJAX timeout when polling for the progress JSON closes #45 --- predict/index.php | 16 ++++++++++++++++ predict/js/pred.js | 24 ++++++++++++++++++++---- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/predict/index.php b/predict/index.php index 0acf444..00d4f70 100644 --- a/predict/index.php +++ b/predict/index.php @@ -1,4 +1,17 @@ diff --git a/predict/js/pred.js b/predict/js/pred.js index 06566db..f123a26 100644 --- a/predict/js/pred.js +++ b/predict/js/pred.js @@ -172,10 +172,26 @@ function getJSONProgress(pred_uuid) { $.ajax({ url:"preds/"+pred_uuid+"/progress.json", dataType:'json', - timeout: 1000, - // complete: function(data, httpstatus) { - // appendDebug(httpstatus); - // }, + timeout: ajaxTimeout, + error: function(xhr, status, error) { + if ( status == "timeout" ) { + appendDebug("Polling for progress JSON timed out"); + // check that we haven't reached maximum allowed timeout + if ( ajaxTimeout < maxAjaxTimeout ) { + // if not, add the delta to the timeout value + newTimeout = ajaxTimeout + deltaAjaxTimeout; + appendDebug("Increasing AJAX timeout from " + ajaxTimeout + + "ms to " + newTimeout + "ms"); + ajaxTimeout = newTimeout; + } else { + // otherwise, throw an error and kill the poller + clearInterval(ajaxEventHandle); + appendDebug("Reached maximum ajaxTimeout value of " + maxAjaxTimeout); + throwError("Tried increasing the AJAX polling timeout to "+maxAjaxTimeout + +"ms but the request still timed out."); + } + } + }, success: processProgress }); }