Browse Source

Merge pull request #40 from pbca26/master

added komodo debug.log truncate on herd start
all-modes
Satinder Grewal 8 years ago
committed by GitHub
parent
commit
8cfef99edb
  1. 29
      main.js
  2. 14
      routes/shepherd.js

29
main.js

@ -31,18 +31,17 @@ if (os.platform() === 'linux') {
// GUI APP settings and starting gui on address http://120.0.0.1:17777 // GUI APP settings and starting gui on address http://120.0.0.1:17777
var shepherd = require('./routes/shepherd'), var shepherd = require('./routes/shepherd'),
guiapp = express(); guiapp = express(),
appConfig = shepherd.loadLocalConfig(); // load app config
guiapp.use(function(req, res, next) { guiapp.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "http://127.0.0.1:17777"); res.header('Access-Control-Allow-Origin', 'http://127.0.0.1:' + appConfig.iguanaAppPort);
res.header("Access-Control-Allow-Headers", "X-Requested-With"); res.header('Access-Control-Allow-Headers', 'X-Requested-With');
res.header("Access-Control-Allow-Credentials", "true"); res.header('Access-Control-Allow-Credentials', 'true');
res.header("Access-Control-Allow-Headers", "Content-Type"); res.header('Access-Control-Allow-Headers', 'Content-Type');
res.header("Access-Control-Allow-Methods", "PUT, GET, POST, DELETE, OPTIONS"); res.header('Access-Control-Allow-Methods', 'PUT, GET, POST, DELETE, OPTIONS'); // TODO: limit allowed methods
next(); next();
}); });
var appConfig = shepherd.loadLocalConfig(); // load app config
// preload.js // preload.js
const _setImmediate = setImmediate, const _setImmediate = setImmediate,
@ -69,7 +68,6 @@ guiapp.get('/', function (req, res) {
var guipath = path.join(__dirname, '/gui'); var guipath = path.join(__dirname, '/gui');
guiapp.use('/gui', express.static(guipath)); guiapp.use('/gui', express.static(guipath));
guiapp.use('/shepherd', shepherd); guiapp.use('/shepherd', shepherd);
/*if (cluster.isMaster && process.env.NODE_ENV !== "development") { /*if (cluster.isMaster && process.env.NODE_ENV !== "development") {
@ -84,18 +82,19 @@ console.log(cluster)
console.log('guiapp listening on port ' + appConfig.iguanaAppPort + '!'); console.log('guiapp listening on port ' + appConfig.iguanaAppPort + '!');
});*/ });*/
var server = require('http').createServer(guiapp); var server = require('http').createServer(guiapp),
var io = require('socket.io').listen(server); io = require('socket.io').listen(server);
server.listen(appConfig.iguanaAppPort, function() { server.listen(appConfig.iguanaAppPort, function() {
console.log('guiapp and sockets.io are listening on port ' + appConfig.iguanaAppPort + '!'); console.log('guiapp and sockets.io are listening on port ' + appConfig.iguanaAppPort + '!');
}); });
io.set('origins', 'http://127.0.0.1:17777'); io.set('origins', 'http://127.0.0.1:17777'); // set origin
io.on('connection', function(client) { io.on('connection', function(client) {
console.log('EDEX GUI is connected...'); console.log('EDEX GUI is connected...');
client.on('event', function(data) { client.on('event', function(data) { // listen for client requests
console.log(data); console.log(data);
}); });
client.on('disconnect', function(data) { client.on('disconnect', function(data) {
@ -107,7 +106,7 @@ io.on('connection', function(client) {
}); });
}); });
shepherd.setIO(io); shepherd.setIO(io); // pass sockets object to shepherd router
//io.emit('an event sent to all connected clients'); //io.emit('an event sent to all connected clients');

14
routes/shepherd.js

@ -311,7 +311,8 @@ shepherd.get('/cache-all', function(req, res, next) {
}); });
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' || coin === 'SYS' ? 2 : 4); var addrCount = outObj.basilisk[coin].addresses ? outObj.basilisk[coin].addresses.length : 0;
callStack[coin] = callStack[coin] + addrCount * (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) {
@ -613,7 +614,8 @@ 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' || coin === 'SYS' ? callsArray.length - 2 : callsArray.length); var addrCount = outObj.basilisk[coin].addresses ? outObj.basilisk[coin].addresses.length : 0;
callStack[coin] = callStack[coin] + addrCount * (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) {
@ -1048,9 +1050,8 @@ shepherd.readDebugLog = function(fileLocation, lastNLines) {
_fs.readFile(fileLocation, 'utf-8', function(err, data) { _fs.readFile(fileLocation, 'utf-8', function(err, data) {
if (err) throw err; if (err) throw err;
// TODO: truncate komodod debug.log on app start var lines = data.trim().split('\n'),
var lines = data.trim().split('\n'); lastLine = lines.slice(lines.length - lastNLines, lines.length).join('\n');
var lastLine = lines.slice(lines.length - lastNLines, lines.length).join('\n');
resolve(lastLine); resolve(lastLine);
}); });
} }
@ -1156,6 +1157,9 @@ function herder(flock, data) {
console.log('komodod flock selected...'); console.log('komodod flock selected...');
console.log('selected data: ' + data); console.log('selected data: ' + data);
// truncate debug.log
fs.unlink(komodoDir + '/debug.log');
pm2.connect(true, function(err) { // start up pm2 god pm2.connect(true, function(err) { // start up pm2 god
if (err) { if (err) {
console.error(err); console.error(err);

Loading…
Cancel
Save