Browse Source

Merge pull request #38 from pbca26/master

added shepherd cache call status
all-modes
Satinder Grewal 8 years ago
committed by GitHub
parent
commit
0736a62d3c
  1. 27
      gui/loading.js
  2. 38
      main.js
  3. 3
      package.json
  4. 68
      routes/shepherd.js

27
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;

38
main.js

@ -33,6 +33,15 @@ if (os.platform() === 'linux') {
var shepherd = require('./routes/shepherd'),
guiapp = express();
guiapp.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "http://127.0.0.1:17777");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
res.header("Access-Control-Allow-Credentials", "true");
res.header("Access-Control-Allow-Headers", "Content-Type");
res.header("Access-Control-Allow-Methods", "PUT, GET, POST, DELETE, OPTIONS");
next();
});
var appConfig = shepherd.loadLocalConfig(); // load app config
// preload.js
@ -71,10 +80,37 @@ guiapp.use('/shepherd', shepherd);
console.log(cluster)
*/
var rungui = guiapp.listen(appConfig.iguanaAppPort, function () {
/*var rungui = guiapp.listen(appConfig.iguanaAppPort, function () {
console.log('guiapp listening on port ' + appConfig.iguanaAppPort + '!');
});*/
var server = require('http').createServer(guiapp);
var io = require('socket.io').listen(server);
server.listen(appConfig.iguanaAppPort, function() {
console.log('guiapp and sockets.io are listening on port ' + appConfig.iguanaAppPort + '!');
});
io.set('origins', 'http://127.0.0.1:17777');
io.on('connection', function(client) {
console.log('EDEX GUI is connected...');
client.on('event', function(data) {
console.log(data);
});
client.on('disconnect', function(data) {
console.log('EDEX GUI is disconnected');
});
client.on('join', function(data) {
console.log(data);
client.emit('messages', 'Sockets server is listening');
});
});
shepherd.setIO(io);
//io.emit('an event sent to all connected clients');
module.exports = guiapp;
// END GUI App Settings

3
package.json

@ -29,10 +29,11 @@
"express": "^4.14.0",
"fix-path": "^2.1.0",
"fs-extra": "^1.0.0",
"graceful-fs": "^4.1.11",
"md5": "^2.2.1",
"mkdirp": "^0.5.1",
"pm2": "^2.3.0",
"ps-node": "^0.1.4",
"read-last-lines": "^1.1.0"
"socket.io": "^1.7.3"
}
}

68
routes/shepherd.js

@ -12,7 +12,6 @@ const electron = require('electron'),
exec = require('child_process').exec,
md5 = require('md5'),
pm2 = require('pm2'),
readLastLines = require('read-last-lines'),
request = require('request'),
async = require('async');
@ -91,6 +90,16 @@ shepherd.get('/appconf', function(req, res, next) {
res.send(obj);
});
shepherd.get('/socket-test', function(req, res, next) {
res.send('Sockets test');
shepherd.io.emit('messages', { 'message': 'legacy of grewal' });
});
// expose sockets obj
shepherd.setIO = function(io) {
shepherd.io = io;
};
/*
* params: pubkey
*/
@ -233,7 +242,7 @@ shepherd.get('/cache-all', function(req, res, next) {
if (response && response.statusCode && response.statusCode === 200) {
outObj.basilisk[coin].addresses = JSON.parse(body).result;
writeCache();
callStack[coin] = callStack[coin] + outObj.basilisk[coin].addresses.length * (coin === 'BTC' ? 2 : 3);
callStack[coin] = callStack[coin] + outObj.basilisk[coin].addresses.length * (coin === 'BTC' || coin === 'SYS' ? 2 : 4);
console.log(coin + ' stack len ' + callStack[coin]);
async.each(outObj.basilisk[coin].addresses, function(address) {
@ -252,14 +261,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 +290,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]--;
@ -424,7 +447,7 @@ shepherd.get('/cache-one', function(req, res, next) {
outObj.basilisk[coin].addresses = JSON.parse(body).result;
console.log(JSON.parse(body).result);
writeCache();
callStack[coin] = callStack[coin] + outObj.basilisk[coin].addresses.length * (coin === 'BTC' ? callsArray.length - 2 : callsArray.length);
callStack[coin] = callStack[coin] + outObj.basilisk[coin].addresses.length * (coin === 'BTC' || coin === 'SYS' ? callsArray.length - 2 : callsArray.length);
console.log(coin + ' stack len ' + callStack[coin]);
async.each(outObj.basilisk[coin].addresses, function(address) {
@ -450,14 +473,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 +502,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 +551,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 +580,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]--;
@ -731,9 +782,14 @@ shepherd.readDebugLog = function(fileLocation, lastNLines) {
reject('readDebugLog error: ' + err);
} else {
console.log('reading ' + fileLocation);
readLastLines
.read(fileLocation, lastNLines)
.then((lines) => resolve(lines));
_fs.readFile(fileLocation, 'utf-8', function(err, data) {
if (err) throw err;
// TODO: truncate komodod debug.log on app start
var lines = data.trim().split('\n');
var lastLine = lines.slice(lines.length - lastNLines, lines.length).join('\n');
resolve(lastLine);
});
}
});
} else {

Loading…
Cancel
Save