Only log warning if main update loop has failed more than once.

This commit is contained in:
softsimon 2020-10-23 16:27:02 +07:00
parent c6d0571be8
commit b4a17693af
No known key found for this signature in database
GPG key ID: 488D7DCFB5A430D7

View file

@ -83,7 +83,7 @@ class Server {
this.setUpHttpApiRoutes();
this.setUpWebsocketHandling();
this.runMempoolIntervalFunctions();
this.runMainUpdateLoop();
fiatConversion.startService();
diskCache.loadMempoolCache();
@ -107,16 +107,21 @@ class Server {
});
}
async runMempoolIntervalFunctions() {
async runMainUpdateLoop() {
try {
await memPool.$updateMemPoolInfo();
await blocks.$updateBlocks();
await memPool.$updateMempool();
setTimeout(this.runMempoolIntervalFunctions.bind(this), config.ELECTRS.POLL_RATE_MS);
setTimeout(this.runMainUpdateLoop.bind(this), config.ELECTRS.POLL_RATE_MS);
this.retryOnElectrsErrorAfterSeconds = 5;
} catch (e) {
logger.warn(`runMempoolIntervalFunctions error: ${(e.message || e)}. Retrying in ${this.retryOnElectrsErrorAfterSeconds} sec.`);
setTimeout(this.runMempoolIntervalFunctions.bind(this), 1000 * this.retryOnElectrsErrorAfterSeconds);
const loggerMsg = `runMainLoop error: ${(e.message || e)}. Retrying in ${this.retryOnElectrsErrorAfterSeconds} sec.`;
if (this.retryOnElectrsErrorAfterSeconds > 5) {
logger.warn(loggerMsg);
} else {
logger.debug(loggerMsg);
}
setTimeout(this.runMainUpdateLoop.bind(this), 1000 * this.retryOnElectrsErrorAfterSeconds);
this.retryOnElectrsErrorAfterSeconds *= 2;
this.retryOnElectrsErrorAfterSeconds = Math.min(this.retryOnElectrsErrorAfterSeconds, 60);
}