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. 3
      gui/loading.js
  2. 38
      main.js
  3. 3
      package.json
  4. 68
      routes/shepherd.js

3
gui/loading.js

@ -70,7 +70,8 @@ function GetAppConf() { // get iguana app conf
async: false, async: false,
type: 'GET', type: 'GET',
url: 'http://127.0.0.1:17777/shepherd/appconf' url: 'http://127.0.0.1:17777/shepherd/appconf'
}).done(function(_data) { })
.done(function(_data) {
console.log('== App Conf Data OutPut =='); console.log('== App Conf Data OutPut ==');
console.log(_data); console.log(_data);
data = _data; data = _data;

38
main.js

@ -33,6 +33,15 @@ if (os.platform() === 'linux') {
var shepherd = require('./routes/shepherd'), var shepherd = require('./routes/shepherd'),
guiapp = express(); 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 var appConfig = shepherd.loadLocalConfig(); // load app config
// preload.js // preload.js
@ -71,9 +80,36 @@ guiapp.use('/shepherd', shepherd);
console.log(cluster) 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 + '!'); 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; module.exports = guiapp;
// END GUI App Settings // END GUI App Settings

3
package.json

@ -29,10 +29,11 @@
"express": "^4.14.0", "express": "^4.14.0",
"fix-path": "^2.1.0", "fix-path": "^2.1.0",
"fs-extra": "^1.0.0", "fs-extra": "^1.0.0",
"graceful-fs": "^4.1.11",
"md5": "^2.2.1", "md5": "^2.2.1",
"mkdirp": "^0.5.1", "mkdirp": "^0.5.1",
"pm2": "^2.3.0", "pm2": "^2.3.0",
"ps-node": "^0.1.4", "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, exec = require('child_process').exec,
md5 = require('md5'), md5 = require('md5'),
pm2 = require('pm2'), pm2 = require('pm2'),
readLastLines = require('read-last-lines'),
request = require('request'), request = require('request'),
async = require('async'); async = require('async');
@ -91,6 +90,16 @@ shepherd.get('/appconf', function(req, res, next) {
res.send(obj); 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 * params: pubkey
*/ */
@ -233,7 +242,7 @@ shepherd.get('/cache-all', function(req, res, next) {
if (response && response.statusCode && response.statusCode === 200) { if (response && response.statusCode && response.statusCode === 200) {
outObj.basilisk[coin].addresses = JSON.parse(body).result; outObj.basilisk[coin].addresses = JSON.parse(body).result;
writeCache(); 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]); console.log(coin + ' stack len ' + callStack[coin]);
async.each(outObj.basilisk[coin].addresses, function(address) { async.each(outObj.basilisk[coin].addresses, function(address) {
@ -250,6 +259,17 @@ shepherd.get('/cache-all', function(req, res, next) {
//console.log(JSON.stringify(dexUrls)); //console.log(JSON.stringify(dexUrls));
console.log(coin + ' address ' + address); console.log(coin + ' address ' + address);
outObj.basilisk[coin][address] = {}; 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(); writeCache();
async.forEachOf(dexUrls, function(dexUrl, key) { async.forEachOf(dexUrls, function(dexUrl, key) {
@ -258,8 +278,10 @@ shepherd.get('/cache-all', function(req, res, next) {
outObj.basilisk[coin][address][key].timestamp && outObj.basilisk[coin][address][key].timestamp &&
checkTimestamp(outObj.basilisk[coin][address][key].timestamp) < cacheGlobLifetime) { checkTimestamp(outObj.basilisk[coin][address][key].timestamp) < cacheGlobLifetime) {
tooEarly = true; tooEarly = true;
outObj.basilisk[coin][address][key].status = 'done';
} }
if (!tooEarly) { if (!tooEarly) {
outObj.basilisk[coin][address][key].status = 'in progress';
request({ request({
url: dexUrl, url: dexUrl,
method: 'GET' method: 'GET'
@ -268,6 +290,7 @@ shepherd.get('/cache-all', function(req, res, next) {
outObj.basilisk[coin][address][key] = {}; outObj.basilisk[coin][address][key] = {};
outObj.basilisk[coin][address][key].data = JSON.parse(body); outObj.basilisk[coin][address][key].data = JSON.parse(body);
outObj.basilisk[coin][address][key].timestamp = Date.now(); // add timestamp outObj.basilisk[coin][address][key].timestamp = Date.now(); // add timestamp
outObj.basilisk[coin][address][key].status = 'done';
console.log(dexUrl); console.log(dexUrl);
console.log(body); console.log(body);
callStack[coin]--; callStack[coin]--;
@ -424,7 +447,7 @@ shepherd.get('/cache-one', function(req, res, next) {
outObj.basilisk[coin].addresses = JSON.parse(body).result; outObj.basilisk[coin].addresses = JSON.parse(body).result;
console.log(JSON.parse(body).result); console.log(JSON.parse(body).result);
writeCache(); 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]); console.log(coin + ' stack len ' + callStack[coin]);
async.each(outObj.basilisk[coin].addresses, function(address) { async.each(outObj.basilisk[coin].addresses, function(address) {
@ -450,14 +473,27 @@ shepherd.get('/cache-one', function(req, res, next) {
writeCache(); 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) { async.forEachOf(_dexUrls, function(dexUrl, key) {
var tooEarly = false; var tooEarly = false;
if (outObj.basilisk[coin][address][key] && if (outObj.basilisk[coin][address][key] &&
outObj.basilisk[coin][address][key].timestamp && outObj.basilisk[coin][address][key].timestamp &&
checkTimestamp(outObj.basilisk[coin][address][key].timestamp) < cacheGlobLifetime) { checkTimestamp(outObj.basilisk[coin][address][key].timestamp) < cacheGlobLifetime) {
tooEarly = true; tooEarly = true;
outObj.basilisk[coin][address][key].status = 'done';
} }
if (!tooEarly) { if (!tooEarly) {
outObj.basilisk[coin][address][key].status = 'in progress';
request({ request({
url: dexUrl, url: dexUrl,
method: 'GET' method: 'GET'
@ -466,6 +502,7 @@ shepherd.get('/cache-one', function(req, res, next) {
outObj.basilisk[coin][address][key] = {}; outObj.basilisk[coin][address][key] = {};
outObj.basilisk[coin][address][key].data = JSON.parse(body); outObj.basilisk[coin][address][key].data = JSON.parse(body);
outObj.basilisk[coin][address][key].timestamp = Date.now(); // add timestamp outObj.basilisk[coin][address][key].timestamp = Date.now(); // add timestamp
outObj.basilisk[coin][address][key].status = 'done';
console.log(dexUrl); console.log(dexUrl);
console.log(body); console.log(body);
callStack[coin]--; callStack[coin]--;
@ -514,14 +551,27 @@ shepherd.get('/cache-one', function(req, res, next) {
} }
console.log(_dexUrls); 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) { async.forEachOf(_dexUrls, function(dexUrl, key) {
var tooEarly = false; var tooEarly = false;
if (outObj.basilisk[coin][address][key] && if (outObj.basilisk[coin][address][key] &&
outObj.basilisk[coin][address][key].timestamp && outObj.basilisk[coin][address][key].timestamp &&
checkTimestamp(outObj.basilisk[coin][address][key].timestamp) < cacheGlobLifetime) { checkTimestamp(outObj.basilisk[coin][address][key].timestamp) < cacheGlobLifetime) {
tooEarly = true; tooEarly = true;
outObj.basilisk[coin][address][key].status = 'done';
} }
if (!tooEarly) { if (!tooEarly) {
outObj.basilisk[coin][address][key].status = 'in progress';
request({ request({
url: dexUrl, url: dexUrl,
method: 'GET' method: 'GET'
@ -530,6 +580,7 @@ shepherd.get('/cache-one', function(req, res, next) {
outObj.basilisk[coin][address][key] = {}; outObj.basilisk[coin][address][key] = {};
outObj.basilisk[coin][address][key].data = JSON.parse(body); outObj.basilisk[coin][address][key].data = JSON.parse(body);
outObj.basilisk[coin][address][key].timestamp = Date.now(); // add timestamp outObj.basilisk[coin][address][key].timestamp = Date.now(); // add timestamp
outObj.basilisk[coin][address][key].status = 'done';
console.log(dexUrl); console.log(dexUrl);
console.log(body); console.log(body);
callStack[coin]--; callStack[coin]--;
@ -731,9 +782,14 @@ shepherd.readDebugLog = function(fileLocation, lastNLines) {
reject('readDebugLog error: ' + err); reject('readDebugLog error: ' + err);
} else { } else {
console.log('reading ' + fileLocation); console.log('reading ' + fileLocation);
readLastLines _fs.readFile(fileLocation, 'utf-8', function(err, data) {
.read(fileLocation, lastNLines) if (err) throw err;
.then((lines) => resolve(lines));
// 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 { } else {

Loading…
Cancel
Save