refactoring

This commit is contained in:
cubedro 2015-03-27 13:38:41 +02:00
parent 9f62909dca
commit 399712168c
2 changed files with 26 additions and 21 deletions

6
app.js
View File

@ -3,13 +3,13 @@ var nodeModel = require('./lib/node');
var node = new nodeModel();
var gracefulShutdown = function() {
console.log("Received kill signal, shutting down gracefully.");
console.warn("Received kill signal, shutting down gracefully.");
node.stop();
console.log("Closed node watcher");
console.info("Closed node watcher");
setTimeout(function(){
console.log("Closed out remaining connections.");
console.info("Closed out remaining connections.");
process.exit(0)
}, 2*1000);
}

View File

@ -13,7 +13,7 @@ var ETH_VERSION,
API_VERSION;
var INSTANCE_NAME = process.env.INSTANCE_NAME;
web3.setProvider(new web3.providers.HttpProvider('http://' + (process.env.RPC_HOST || 'localhost') + ':' + (process.env.RPC_PORT || '8080')));
web3.setProvider(new web3.providers.HttpProvider('http://' + (process.env.RPC_HOST || 'localhost') + ':' + (process.env.RPC_PORT || '8545')));
Socket = Primus.createSocket({
transformer: 'websockets',
@ -42,7 +42,7 @@ function Node()
API_VERSION = web3.version.api;
}
catch (err) {
console.log("couldn't get Version");
console.error("couldn't get Version");
}
this.info = {
@ -88,16 +88,21 @@ function Node()
socket.on('open', function open() {
socket.emit('hello', { id: self.id, info: self.info, secret: WS_SECRET });
console.log('The connection has been opened.');
console.log('Trying to login');
}).on('end', function end() {
console.info('The connection has been opened.');
console.info('Trying to login');
})
.on('end', function end() {
self._socket = false;
}).on('error', function error(err) {
console.log(err);
}).on('reconnecting', function reconnecting(opts) {
console.log('We are scheduling a reconnect operation', opts);
}).on('data', function incoming(data) {
console.log('Received some data', data);
console.error('Socket connection closed');
})
.on('error', function error(err) {
console.error(err);
})
.on('reconnecting', function reconnecting(opts) {
console.warn('We are scheduling a reconnect operation', opts);
})
.on('data', function incoming(data) {
console.info('Received some data', data);
});
socket.on('ready', function()
@ -105,7 +110,7 @@ function Node()
self._socket = true;
self.sendUpdate(true);
console.log('The connection has been established.');
console.info('The connection has been established.');
});
this.init();
@ -134,7 +139,7 @@ Node.prototype.isActive = function()
code: '1',
msg: err
});
console.log(err);
console.error(err);
}
this.stats.active = false;
@ -158,7 +163,7 @@ Node.prototype.getBlock = function(number)
if(typeof number === 'undefined'){
try {
number = parseInt(web3.eth.blockNumber);
number = web3.eth.blockNumber;
if(number === this.stats.block.number + 1)
return this.stats.block;
@ -168,7 +173,7 @@ Node.prototype.getBlock = function(number)
code: '3',
msg: err
});
console.log(err);
console.error(err);
}
}
@ -187,7 +192,7 @@ Node.prototype.getBlock = function(number)
code: '2',
msg: err
});
console.log(err);
console.error(err);
}
return block;
@ -354,7 +359,7 @@ Node.prototype.setWatches = function()
this.updateInterval = setInterval(function(){
self.update();
}, 1000);
}, 5000);
}
Node.prototype.emit = function(message, payload)
@ -364,7 +369,7 @@ Node.prototype.emit = function(message, payload)
socket.emit(message, payload);
}
catch (err) {
console.log(err);
console.error(err);
}
}
}