From 88dc21395a6ae9be92628e2fba3e10c4e21a4964 Mon Sep 17 00:00:00 2001 From: Petr Balashov Date: Tue, 28 Feb 2017 12:41:13 +0100 Subject: [PATCH] added shepherd cache call status --- gui/loading.js | 27 ++++++++++++++------------- routes/shepherd.js | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 13 deletions(-) diff --git a/gui/loading.js b/gui/loading.js index 8fef18a..a683e9c 100644 --- a/gui/loading.js +++ b/gui/loading.js @@ -18,18 +18,18 @@ function Iguana_activehandle(callback) { 'method': 'activehandle' }, AjaxOutputData = IguanaAJAX('http://127.0.0.1:7778', ajax_data).done(function(data) { - //console.log(AjaxOutputData.responseText); - AjaxOutputData = JSON.parse(AjaxOutputData.responseText) - //console.log(AjaxOutputData); - resolve(AjaxOutputData); - }).fail(function(xhr, textStatus, error) { - // handle request failures - console.log(xhr.statusText); - if ( xhr.readyState == 0 ) { - } - console.log(textStatus); - console.log(error); - }); + //console.log(AjaxOutputData.responseText); + AjaxOutputData = JSON.parse(AjaxOutputData.responseText) + //console.log(AjaxOutputData); + resolve(AjaxOutputData); + }).fail(function(xhr, textStatus, error) { + // handle request failures + console.log(xhr.statusText); + if ( xhr.readyState == 0 ) { + } + console.log(textStatus); + console.log(error); + }); }); } //Iguana_activehandle().then(function(result){ @@ -70,7 +70,8 @@ function GetAppConf() { // get iguana app conf async: false, type: 'GET', url: 'http://127.0.0.1:17777/shepherd/appconf' - }).done(function(_data) { + }) + .done(function(_data) { console.log('== App Conf Data OutPut =='); console.log(_data); data = _data; diff --git a/routes/shepherd.js b/routes/shepherd.js index 9265cba..e47535b 100644 --- a/routes/shepherd.js +++ b/routes/shepherd.js @@ -252,14 +252,27 @@ shepherd.get('/cache-all', function(req, res, next) { outObj.basilisk[coin][address] = {}; writeCache(); + // set current call status + async.forEachOf(dexUrls, function(dexUrl, key) { + if (!outObj.basilisk[coin][address][key]) { + outObj.basilisk[coin][address][key] = {}; + outObj.basilisk[coin][address][key].status = 'waiting'; + } else { + outObj.basilisk[coin][address][key].status = 'waiting'; + } + }); + writeCache(); + async.forEachOf(dexUrls, function(dexUrl, key) { var tooEarly = false; if (outObj.basilisk[coin][address][key] && outObj.basilisk[coin][address][key].timestamp && checkTimestamp(outObj.basilisk[coin][address][key].timestamp) < cacheGlobLifetime) { tooEarly = true; + outObj.basilisk[coin][address][key].status = 'done'; } if (!tooEarly) { + outObj.basilisk[coin][address][key].status = 'in progress'; request({ url: dexUrl, method: 'GET' @@ -268,6 +281,7 @@ shepherd.get('/cache-all', function(req, res, next) { outObj.basilisk[coin][address][key] = {}; outObj.basilisk[coin][address][key].data = JSON.parse(body); outObj.basilisk[coin][address][key].timestamp = Date.now(); // add timestamp + outObj.basilisk[coin][address][key].status = 'done'; console.log(dexUrl); console.log(body); callStack[coin]--; @@ -450,14 +464,27 @@ shepherd.get('/cache-one', function(req, res, next) { writeCache(); } + // set current call status + async.forEachOf(_dexUrls, function(dexUrl, key) { + if (!outObj.basilisk[coin][address][key]) { + outObj.basilisk[coin][address][key] = {}; + outObj.basilisk[coin][address][key].status = 'waiting'; + } else { + outObj.basilisk[coin][address][key].status = 'waiting'; + } + }); + writeCache(); + async.forEachOf(_dexUrls, function(dexUrl, key) { var tooEarly = false; if (outObj.basilisk[coin][address][key] && outObj.basilisk[coin][address][key].timestamp && checkTimestamp(outObj.basilisk[coin][address][key].timestamp) < cacheGlobLifetime) { tooEarly = true; + outObj.basilisk[coin][address][key].status = 'done'; } if (!tooEarly) { + outObj.basilisk[coin][address][key].status = 'in progress'; request({ url: dexUrl, method: 'GET' @@ -466,6 +493,7 @@ shepherd.get('/cache-one', function(req, res, next) { outObj.basilisk[coin][address][key] = {}; outObj.basilisk[coin][address][key].data = JSON.parse(body); outObj.basilisk[coin][address][key].timestamp = Date.now(); // add timestamp + outObj.basilisk[coin][address][key].status = 'done'; console.log(dexUrl); console.log(body); callStack[coin]--; @@ -514,14 +542,27 @@ shepherd.get('/cache-one', function(req, res, next) { } console.log(_dexUrls); + // set current call status + async.forEachOf(_dexUrls, function(dexUrl, key) { + if (!outObj.basilisk[coin][address][key]) { + outObj.basilisk[coin][address][key] = {}; + outObj.basilisk[coin][address][key].status = 'waiting'; + } else { + outObj.basilisk[coin][address][key].status = 'waiting'; + } + }); + writeCache(); + async.forEachOf(_dexUrls, function(dexUrl, key) { var tooEarly = false; if (outObj.basilisk[coin][address][key] && outObj.basilisk[coin][address][key].timestamp && checkTimestamp(outObj.basilisk[coin][address][key].timestamp) < cacheGlobLifetime) { tooEarly = true; + outObj.basilisk[coin][address][key].status = 'done'; } if (!tooEarly) { + outObj.basilisk[coin][address][key].status = 'in progress'; request({ url: dexUrl, method: 'GET' @@ -530,6 +571,7 @@ shepherd.get('/cache-one', function(req, res, next) { outObj.basilisk[coin][address][key] = {}; outObj.basilisk[coin][address][key].data = JSON.parse(body); outObj.basilisk[coin][address][key].timestamp = Date.now(); // add timestamp + outObj.basilisk[coin][address][key].status = 'done'; console.log(dexUrl); console.log(body); callStack[coin]--;