From a4f4147b6fe5f2a003a61cf8a8f7508c94130b31 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 26 May 2014 22:49:54 +0200 Subject: WIP --- script/taskmanager.js | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) (limited to 'script') diff --git a/script/taskmanager.js b/script/taskmanager.js index fdbe4107..a34b3aa4 100644 --- a/script/taskmanager.js +++ b/script/taskmanager.js @@ -1,13 +1,16 @@ var tmItems = false; var tmErrors = 0; var TM_MAX_ERRORS = 5; +var tmIsRunning = false; function tmInit() { tmItems = $("div[data-tm-id]"); - if (tmItems.length === 0) return; + if (tmItems.length === 0) + return; tmItems.each(function(i, item) { item = $(item); + if (item.find('.data-tm-icon').length !== 0) return; if (item.is('[data-tm-progress]')) { item.append('
'); } @@ -16,7 +19,9 @@ function tmInit() } item.prepend(''); }); - setTimeout(tmUpdate, 100); + if (!tmIsRunning) + setTimeout(tmUpdate, 50); + tmIsRunning = true; } function tmUpdate() @@ -25,19 +30,25 @@ function tmUpdate() tmItems.each(function(i, item) { item = $(item); var id = item.attr('data-tm-id'); - if (typeof id === 'undefined' || id === false || id === '') return; + if (typeof id === 'undefined' || id === false || id === '') + return; active.push(id); }); - if (active.length === 0) return; - $.post('api.php?do=taskmanager', { 'ids[]' : active, token : TOKEN }, function (data, status) { + if (active.length === 0) + return; + $.post('api.php?do=taskmanager', {'ids[]': active, token: TOKEN}, function(data, status) { // POST success - if (tmResult(data, status)) { + tmIsRunning = tmResult(data, status) + if (tmIsRunning) { setTimeout(tmUpdate, 1000); } - }, 'json').fail(function (jqXHR, textStatus, errorThrown) { + }, 'json').fail(function(jqXHR, textStatus, errorThrown) { // POST failure console.log("TaskManager Error: " + textStatus + " - " + errorThrown); - if (++tmErrors < TM_MAX_ERRORS) setTimeout(tmUpdate, 2000); + if (++tmErrors < TM_MAX_ERRORS) + setTimeout(tmUpdate, 2000); + else + tmIsRunning = false; }); } @@ -60,7 +71,8 @@ function tmResult(data, status) var counter = 0; for (var idx in data.tasks) { var task = data.tasks[idx]; - if (!task.id) continue; + if (!task.id) + continue; counter++; if (lastRunOnError) { task.statusCode = 'TASK_ERROR'; @@ -71,7 +83,8 @@ function tmResult(data, status) --tmErrors; } var obj = $('div[data-tm-id="' + task.id + '"]'); - if (!obj) continue; + if (!obj) + continue; if (task.statusCode !== 'TASK_WAITING' && task.statusCode !== 'TASK_PROCESSING') { obj.attr('data-tm-id', ''); } -- cgit v1.2.3-55-g7522