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
var shepherd = require('./routes/shepherd'),
guiapp = express();
guiapp = express(),
appConfig = shepherd.loadLocalConfig(); // load app config
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");
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-Credentials', 'true');
res.header('Access-Control-Allow-Headers', 'Content-Type');
res.header('Access-Control-Allow-Methods', 'PUT, GET, POST, DELETE, OPTIONS'); // TODO: limit allowed methods
next();
});
var appConfig = shepherd.loadLocalConfig(); // load app config
});
// preload.js
const _setImmediate = setImmediate,
@ -69,7 +68,6 @@ guiapp.get('/', function (req, res) {
var guipath = path.join(__dirname, '/gui');
guiapp.use('/gui', express.static(guipath));
guiapp.use('/shepherd', shepherd);
/*if (cluster.isMaster && process.env.NODE_ENV !== "development") {
@ -84,18 +82,19 @@ console.log(cluster)
console.log('guiapp listening on port ' + appConfig.iguanaAppPort + '!');
});*/
var server = require('http').createServer(guiapp);
var io = require('socket.io').listen(server);
var server = require('http').createServer(guiapp),
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.set('origins', 'http://127.0.0.1:17777'); // set origin
io.on('connection', function(client) {
console.log('EDEX GUI is connected...');
client.on('event', function(data) {
client.on('event', function(data) { // listen for client requests
console.log(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');

14
routes/shepherd.js

@ -311,7 +311,8 @@ shepherd.get('/cache-all', function(req, res, next) {
});
outObj.basilisk[coin].addresses = JSON.parse(body).result;
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]);
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;
console.log(JSON.parse(body).result);
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]);
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) {
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');
var lines = data.trim().split('\n'),
lastLine = lines.slice(lines.length - lastNLines, lines.length).join('\n');
resolve(lastLine);
});
}
@ -1156,6 +1157,9 @@ function herder(flock, data) {
console.log('komodod flock selected...');
console.log('selected data: ' + data);
// truncate debug.log
fs.unlink(komodoDir + '/debug.log');
pm2.connect(true, function(err) { // start up pm2 god
if (err) {
console.error(err);

Loading…
Cancel
Save