Merge pull request #52 from bluecircle/master

store proxy state in redis and restore on restart; disable example pool
This commit is contained in:
Matthew Little 2014-04-09 10:02:15 -06:00
commit b41154be47
2 changed files with 16 additions and 6 deletions

View File

@ -74,7 +74,18 @@ module.exports = function(logger){
} }
); );
proxySwitch[algo].currentPool = newCoin; proxySwitch[algo].currentPool = newCoin;
//TODO write new pool to REDIS
var redisClient = redis.createClient(6379, "localhost")
redisClient.on('ready', function(){
redisClient.hset('proxyState', algo, newCoin, function(error, obj) {
if (error) {
logger.error(logSystem, logComponent, logSubCat, 'Redis error writing proxy config: ' + JSON.stringify(err))
}
else {
logger.debug(logSystem, logComponent, logSubCat, 'Last proxy state saved to redis for ' + algo);
}
});
});
} }
break; break;
} }
@ -195,7 +206,7 @@ module.exports = function(logger){
// on the last pool it was using when reloaded or restarted // on the last pool it was using when reloaded or restarted
// //
logger.debug(logSystem, logComponent, logSubCat, 'Loading last proxy state from redis'); logger.debug(logSystem, logComponent, logSubCat, 'Loading last proxy state from redis');
var redisClient = redis.createClient(6379, "localhost") //TODO figure out where redis config will come from for such things var redisClient = redis.createClient(6379, "localhost")
redisClient.on('ready', function(){ redisClient.on('ready', function(){
redisClient.hgetall("proxyState", function(error, obj) { redisClient.hgetall("proxyState", function(error, obj) {
if (error) { if (error) {
@ -217,7 +228,7 @@ module.exports = function(logger){
Object.keys(portalConfig.proxy).forEach(function(algorithm) { Object.keys(portalConfig.proxy).forEach(function(algorithm) {
if (portalConfig.proxy[algorithm].enabled === true) { if (portalConfig.proxy[algorithm].enabled === true) {
var initalPool = proxyState.hasOwnProperty(algorithm) ? proxyState[algorithm].currentPool : _this.getFirstPoolForAlgorithm(algorithm); var initalPool = proxyState.hasOwnProperty(algorithm) ? proxyState[algorithm] : _this.getFirstPoolForAlgorithm(algorithm);
proxySwitch[algorithm] = { proxySwitch[algorithm] = {
port: portalConfig.proxy[algorithm].port, port: portalConfig.proxy[algorithm].port,
currentPool: initalPool, currentPool: initalPool,
@ -263,7 +274,6 @@ module.exports = function(logger){
}).on('error', function(err){ }).on('error', function(err){
logger.debug(logSystem, logComponent, logSubCat, 'Pool configuration failed: ' + err); logger.debug(logSystem, logComponent, logSubCat, 'Pool configuration failed: ' + err);
}); });
redisClient.quit();
} }
this.getFirstPoolForAlgorithm = function(algorithm) { this.getFirstPoolForAlgorithm = function(algorithm) {

View File

@ -1,5 +1,5 @@
{ {
"enabled": true, "enabled": false,
"coin": "litecoin.json", "coin": "litecoin.json",
"address": "n4jSe18kZMCdGcZqaYprShXW6EH1wivUK1", "address": "n4jSe18kZMCdGcZqaYprShXW6EH1wivUK1",
@ -92,4 +92,4 @@
"protocolVersion": 70002, "protocolVersion": 70002,
"magic": "fcc1b7dc" "magic": "fcc1b7dc"
} }
} }