From 1ced39b13e00e13e4234b8bd89508cc9be0a11e7 Mon Sep 17 00:00:00 2001 From: cgeek <cem.moreau@gmail.com> Date: Tue, 3 Jan 2017 22:07:22 +0100 Subject: [PATCH] [fix] Handling again the regular tasks start/stop --- app/service/PeeringService.js | 27 ++++++++++++++------------- server.js | 1 + 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/app/service/PeeringService.js b/app/service/PeeringService.js index d13604598..1750018be 100644 --- a/app/service/PeeringService.js +++ b/app/service/PeeringService.js @@ -531,6 +531,20 @@ function PeeringService(server) { } function syncBlock(callback, pubkey) { + + // Eventually change the interval duration + const minutesElapsed = Math.ceil((Date.now() - programStart) / (60 * 1000)); + const FACTOR = Math.sin((minutesElapsed / constants.PULLING_INTERVAL_TARGET) * (Math.PI / 2)); + // Make the interval always higher than before + const pullingTheoreticalIntervalNow = Math.max(parseInt(Math.max(FACTOR * constants.PULLING_INTERVAL_TARGET, constants.PULLING_MINIMAL_DELAY)), pullingActualIntervalDuration); + if (pullingTheoreticalIntervalNow !== pullingActualIntervalDuration) { + pullingActualIntervalDuration = pullingTheoreticalIntervalNow; + // Change the interval + if (syncBlockInterval) + clearInterval(syncBlockInterval); + syncBlockInterval = setInterval(() => syncBlockFifo.push(syncBlock), 1000 * pullingActualIntervalDuration); + } + currentSyncP = querablep(co(function *() { try { let current = yield dal.getCurrentBlockOrNull(); @@ -644,19 +658,6 @@ function PeeringService(server) { } pullingEvent('end', current.number); } - - // Eventually change the interval duration - const minutesElapsed = Math.ceil((Date.now() - programStart) / (60 * 1000)); - const FACTOR = Math.sin((minutesElapsed / constants.PULLING_INTERVAL_TARGET) * (Math.PI / 2)); - // Make the interval always higher than before - const pullingTheoreticalIntervalNow = Math.max(parseInt(Math.max(FACTOR * constants.PULLING_INTERVAL_TARGET, constants.PULLING_MINIMAL_DELAY)), pullingActualIntervalDuration); - if (pullingTheoreticalIntervalNow !== pullingActualIntervalDuration) { - pullingActualIntervalDuration = pullingTheoreticalIntervalNow; - // Change the interval - if (syncBlockInterval) - clearInterval(syncBlockInterval); - syncBlockInterval = setInterval(() => syncBlockFifo.push(syncBlock), 1000 * pullingActualIntervalDuration); - } logger.info('Will pull blocks from the network in %s min %s sec', Math.floor(pullingActualIntervalDuration / 60), Math.floor(pullingActualIntervalDuration % 60)); callback && callback(); diff --git a/server.js b/server.js index 32a5e668a..1242c6bd5 100644 --- a/server.js +++ b/server.js @@ -533,6 +533,7 @@ function Server (dbConf, overrideConf) { if (that.conf.participate) { that.stopBlockComputation(); } + return that.PeeringService.stopRegular(); }); } -- GitLab