From 3fab1673ff503035d11194798cd81875183f719b Mon Sep 17 00:00:00 2001 From: Alexander Blair Date: Sun, 26 Feb 2017 10:20:11 -0800 Subject: [PATCH] Payment Update Moving payment timers into the database Adding the last payment timer cycle to the stats --- lib/api.js | 5 +++-- lib/payments.js | 9 +++++---- sql_sync/config_entries.json | 16 ++++++++++++++++ 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/lib/api.js b/lib/api.js index 807f581..7c4aec3 100644 --- a/lib/api.js +++ b/lib/api.js @@ -75,7 +75,8 @@ app.get('/pool/stats', function (req, res) { let localCache = global.database.getCache('pool_stats_global'); delete(localCache.minerHistory); delete(localCache.hashHistory); - res.json({pool_list: pool_list, pool_statistics: localCache}); + let lastPayment = global.database.getCache('lastPaymentCycle'); + res.json({pool_list: pool_list, pool_statistics: localCache, last_payment: !lastPayment ? 0 : lastPayment}); }); app.get('/pool/chart/hashrate', function (req, res) { @@ -601,7 +602,7 @@ adminRoutes.get('/stats', function (req, res) { }); return callback(null); } - ], function (err) { + ], function () { return res.json(intCache); }); }); diff --git a/lib/payments.js b/lib/payments.js index 72c0288..a48a9b0 100644 --- a/lib/payments.js +++ b/lib/payments.js @@ -307,7 +307,7 @@ let paymentQueue = async.queue(function (paymentDetails, callback) { if(!extraPaymentRound){ setTimeout(function(){ makePayments(); - }, 1800000); + }, global.config.payout.timerRetry * 60 * 1000); } extraPaymentRound = true; return callback(false); @@ -342,7 +342,8 @@ let paymentQueue = async.queue(function (paymentDetails, callback) { paymentQueue.drain = function(){ extraPaymentRound = false; - paymentTimer = setInterval(makePayments, 7200000); + paymentTimer = setInterval(makePayments, global.config.payout.timer * 60 * 1000); + global.database.setCache('lastPaymentCycle', Math.floor(Date.now()/1000)); }; function updateShapeshiftCompletion() { @@ -638,7 +639,7 @@ function makePayments() { mixin: global.config.payout.mixIn }; console.log("Paying out: " + paymentDetails.destinations.length + " people"); - paymentQueue.push(paymentDetails, function (body) { + paymentQueue.push(paymentDetails, function (body) { //jshint ignore:line // This is the only section that could potentially contain multiple txns. Lets do this safely eh? if (body.fee && body.fee > 10) { debug("Made it to the SQL insert for transactions"); @@ -683,7 +684,7 @@ function init() { }); }, 60000); setInterval(determineBestExchange, 60000); - paymentTimer = setInterval(makePayments, 7200000); + console.log("Setting the payment timer to: " + global.config.payout.timer + " minutes with a: " + global.config.timerRetry + " minute delay if the wallet is out of money"); makePayments(); } diff --git a/sql_sync/config_entries.json b/sql_sync/config_entries.json index 98eaafb..dbf34fe 100644 --- a/sql_sync/config_entries.json +++ b/sql_sync/config_entries.json @@ -534,5 +534,21 @@ "item_value": "NodeJS-Pool Administration Team", "item_type": "string", "Item_desc": "Signature line for the emails." + }, + { + "id": 73, + "module": "payout", + "item": "timer", + "item_value": "120", + "item_type": "int", + "Item_desc": "Number of minutes between main payment daemon cycles" + }, + { + "id": 74, + "module": "payout", + "item": "timerRetry", + "item_value": "25", + "item_type": "int", + "Item_desc": "Number of minutes between payment daemon retrying due to not enough funds" } ]