From fb9ac8080b2b4317ae6358e2f9d6bd0b284ac0a1 Mon Sep 17 00:00:00 2001 From: sairajzero Date: Sat, 7 May 2022 00:15:34 +0530 Subject: [PATCH] Fixed: price storeHistory - price.storeHistory interval will trigger only when node is master --- src/market.js | 2 ++ src/price.js | 20 ++++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/market.js b/src/market.js index e9fc01d..f096f40 100644 --- a/src/market.js +++ b/src/market.js @@ -662,6 +662,7 @@ periodicProcess.start = function() { periodicProcess.stop(); periodicProcess(); assetList.forEach(asset => coupling.initiate(asset)); + coupling.price.storeHistory.start(); periodicProcess.instance = setInterval(periodicProcess, PERIOD_INTERVAL); }; @@ -671,6 +672,7 @@ periodicProcess.stop = function() { delete periodicProcess.instance; } coupling.stopAll(); + coupling.price.storeHistory.stop(); }; function blockchainReCheck() { diff --git a/src/price.js b/src/price.js index e416ef5..2101394 100644 --- a/src/price.js +++ b/src/price.js @@ -25,10 +25,21 @@ function storeHistory(asset, rate) { DB.query("INSERT INTO PriceHistory (asset, rate) VALUE (?, ?)", [asset, rate.toFixed(8)]) .then(_ => null).catch(error => console.error(error)) } -setInterval(() => { - for (let asset in currentRate) - storeHistory(asset, currentRate[asset]); -}, REC_HISTORY_INTERVAL); + +storeHistory.start = function() { + storeHistory.stop(); + storeHistory.instance = setInterval(() => { + for (let asset in currentRate) + storeHistory(asset, currentRate[asset]); + }, REC_HISTORY_INTERVAL); +} + +storeHistory.stop = function() { + if (storeHistory.instance !== undefined) { + clearInterval(storeHistory.instance); + delete storeHistory.instance; + } +} function getPastRate(asset, hrs = 24) { return new Promise((resolve, reject) => { @@ -196,6 +207,7 @@ function checkForRatedSellers(asset) { module.exports = { getRates, getHistory, + storeHistory, updateLastTime, MIN_TIME, noOrder(asset, buy, sell) {