Fixed: price storeHistory

- price.storeHistory interval will trigger only when node is master
This commit is contained in:
sairajzero 2022-05-07 00:15:34 +05:30
parent 54470b42d7
commit fb9ac8080b
2 changed files with 18 additions and 4 deletions

View File

@ -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() {

View File

@ -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(() => {
storeHistory.start = function() {
storeHistory.stop();
storeHistory.instance = setInterval(() => {
for (let asset in currentRate)
storeHistory(asset, currentRate[asset]);
}, REC_HISTORY_INTERVAL);
}, 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) {