From a91df8a2b282bdca4d11b14e1316528cd1413e0e Mon Sep 17 00:00:00 2001 From: sairajzero Date: Sat, 24 Jul 2021 01:04:20 +0530 Subject: [PATCH] Bug fix - Promisified the refresher invoke fn. - Connect to next node upon 1st refresher resolve --- src/intra.js | 3 ++- src/main.js | 31 ++++++++++++++++++++----------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/intra.js b/src/intra.js index 4c7b146..c94fb2c 100644 --- a/src/intra.js +++ b/src/intra.js @@ -525,7 +525,7 @@ function deleteMigratedData(old_sn, vectorClock, receiverID, from, packet) { }; function initiateRefresh() { - refresher.invoke(false); + refresher.invoke(false).then(_ => null).catch(_ => null); }; //Forward incoming to next node @@ -682,6 +682,7 @@ dataMigration.intimateAllNodes = function() { //-----EXPORTS----- module.exports = { + reconnectNextNode, processTaskFromSupernode, forwardToNextNode, dataMigration, diff --git a/src/main.js b/src/main.js index 471d83a..5793072 100644 --- a/src/main.js +++ b/src/main.js @@ -34,7 +34,8 @@ function startNode() { floGlobals.appList = base.appList; floGlobals.appSubAdmins = base.appSubAdmins; refreshData.base = base; - refreshData.invoke(); + refreshData.invoke() + .then(_ => intra.reconnectNextNode()).catch(_ => null) //Start Server const server = new Server(config["port"], client, intra); server.refresher = refreshData; @@ -57,20 +58,28 @@ const refreshData = { count: null, base: null, invoke(flag = true) { - this.count = floGlobals.sn_config.refreshDelay; - console.info("Refresher processor has started at " + Date()); - refreshBlockchainData(this.base, flag).then(result => { - console.log(result); - diskCleanUp(this.base) - .then(result => console.log(result)) - .catch(warn => console.warn(warn)) - .finally(_ => console.info("Refresher processor has finished at " + Date())); - }).catch(error => console.error(error)); + return new Promise((resolve, reject) => { + this.count = floGlobals.sn_config.refreshDelay; + console.info("Refresher processor has started at " + Date()); + refreshBlockchainData(this.base, flag).then(result => { + console.log(result); + diskCleanUp(this.base) + .then(result => console.log(result)) + .catch(warn => console.warn(warn)) + .finally(_ => { + console.info("Refresher processor has finished at " + Date()); + resolve(true); + }); + }).catch(error => { + console.error(error); + reject(false); + }); + }); }, get countdown() { this.count--; if (this.count <= 0) - this.invoke(); + this.invoke().then(_ => null).catch(_ => null); } };