Skip to content
Snippets Groups Projects
Commit 1ced39b1 authored by Cédric Moreau's avatar Cédric Moreau
Browse files

[fix] Handling again the regular tasks start/stop

parent 3d26c913
No related branches found
No related tags found
No related merge requests found
...@@ -531,6 +531,20 @@ function PeeringService(server) { ...@@ -531,6 +531,20 @@ function PeeringService(server) {
} }
function syncBlock(callback, pubkey) { 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 *() { currentSyncP = querablep(co(function *() {
try { try {
let current = yield dal.getCurrentBlockOrNull(); let current = yield dal.getCurrentBlockOrNull();
...@@ -644,19 +658,6 @@ function PeeringService(server) { ...@@ -644,19 +658,6 @@ function PeeringService(server) {
} }
pullingEvent('end', current.number); 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)); logger.info('Will pull blocks from the network in %s min %s sec', Math.floor(pullingActualIntervalDuration / 60), Math.floor(pullingActualIntervalDuration % 60));
callback && callback(); callback && callback();
......
...@@ -533,6 +533,7 @@ function Server (dbConf, overrideConf) { ...@@ -533,6 +533,7 @@ function Server (dbConf, overrideConf) {
if (that.conf.participate) { if (that.conf.participate) {
that.stopBlockComputation(); that.stopBlockComputation();
} }
return that.PeeringService.stopRegular();
}); });
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment