Refresh blockchain-data periodically
- Refresh the blockchain data atleast once every 1 hour. - If regular countdown (based on requests) occurs, then automatically reset the blockchain-refresh timer.
This commit is contained in:
parent
c8130e887e
commit
4ad512fc1d
15
src/main.js
15
src/main.js
@ -11,6 +11,7 @@ const client = require('./client');
|
|||||||
const Server = require('./server');
|
const Server = require('./server');
|
||||||
|
|
||||||
var DB; //Container for Database object
|
var DB; //Container for Database object
|
||||||
|
const INTERVAL_REFRESH_TIME = 1 * 60 * 60 * 1000; //1 hr
|
||||||
|
|
||||||
function startNode() {
|
function startNode() {
|
||||||
//Set myPrivKey, myPubKey, myFloID
|
//Set myPrivKey, myPubKey, myFloID
|
||||||
@ -57,13 +58,19 @@ function loadBase() {
|
|||||||
const refreshData = {
|
const refreshData = {
|
||||||
count: null,
|
count: null,
|
||||||
base: null,
|
base: null,
|
||||||
|
refresh_instance: null,
|
||||||
invoke(flag = true) {
|
invoke(flag = true) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
const self = this;
|
||||||
console.info("Refresher processor has started at " + Date());
|
console.info("Refresher processor has started at " + Date());
|
||||||
refreshBlockchainData(this.base, flag).then(result => {
|
if (self.refresh_instance !== null) {
|
||||||
|
clearInterval(self.refresh_instance);
|
||||||
|
self.refresh_instance = null;
|
||||||
|
}
|
||||||
|
refreshBlockchainData(self.base, flag).then(result => {
|
||||||
console.log(result);
|
console.log(result);
|
||||||
this.count = floGlobals.sn_config.refreshDelay;
|
self.count = floGlobals.sn_config.refreshDelay;
|
||||||
diskCleanUp(this.base)
|
diskCleanUp(self.base)
|
||||||
.then(result => console.log(result))
|
.then(result => console.log(result))
|
||||||
.catch(warn => console.warn(warn))
|
.catch(warn => console.warn(warn))
|
||||||
.finally(_ => {
|
.finally(_ => {
|
||||||
@ -73,6 +80,8 @@ const refreshData = {
|
|||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
reject(false);
|
reject(false);
|
||||||
|
}).finally(_ => {
|
||||||
|
self.refresh_instance = setInterval(() => refreshBlockchainData(self.base, true), INTERVAL_REFRESH_TIME)
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user