From 2f8620a454c3d96f7db7cd0199286f6c95a95caf Mon Sep 17 00:00:00 2001 From: Jerry Brady Date: Wed, 9 Apr 2014 01:33:46 +0000 Subject: [PATCH] store proxy state in redis and restore on restart; disable example pool --- libs/poolWorker.js | 18 ++++++++++++++---- pool_configs/litecoin_example.json | 4 ++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/libs/poolWorker.js b/libs/poolWorker.js index 2464755..4855507 100644 --- a/libs/poolWorker.js +++ b/libs/poolWorker.js @@ -74,7 +74,18 @@ module.exports = function(logger){ } ); 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; } @@ -195,7 +206,7 @@ module.exports = function(logger){ // on the last pool it was using when reloaded or restarted // 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.hgetall("proxyState", function(error, obj) { if (error) { @@ -217,7 +228,7 @@ module.exports = function(logger){ Object.keys(portalConfig.proxy).forEach(function(algorithm) { 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] = { port: portalConfig.proxy[algorithm].port, currentPool: initalPool, @@ -263,7 +274,6 @@ module.exports = function(logger){ }).on('error', function(err){ logger.debug(logSystem, logComponent, logSubCat, 'Pool configuration failed: ' + err); }); - redisClient.quit(); } this.getFirstPoolForAlgorithm = function(algorithm) { diff --git a/pool_configs/litecoin_example.json b/pool_configs/litecoin_example.json index 06601a5..0e7536e 100644 --- a/pool_configs/litecoin_example.json +++ b/pool_configs/litecoin_example.json @@ -1,5 +1,5 @@ { - "enabled": true, + "enabled": false, "coin": "litecoin.json", "address": "n4jSe18kZMCdGcZqaYprShXW6EH1wivUK1", @@ -92,4 +92,4 @@ "protocolVersion": 70002, "magic": "fcc1b7dc" } -} \ No newline at end of file +}