X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Fbase-request-scheduler.js;h=4709c7960fee4c97b05c0e377b1ee11e81b3be06;hb=72329aaa28bcbb678443900233cc47cff7ba1509;hp=d15680c25a5789b227e29eb56b5e8eaa120e148e;hpb=9e167724f7e933f41d9ea2e1c31772bf4c560a28;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/base-request-scheduler.js b/server/lib/base-request-scheduler.js index d15680c25..4709c7960 100644 --- a/server/lib/base-request-scheduler.js +++ b/server/lib/base-request-scheduler.js @@ -8,10 +8,10 @@ const logger = require('../helpers/logger') const requests = require('../helpers/requests') module.exports = class BaseRequestScheduler { - constructor (options) { this.lastRequestTimestamp = 0 this.timer = null + this.requestInterval = constants.REQUESTS_INTERVAL } activate () { @@ -21,7 +21,7 @@ module.exports = class BaseRequestScheduler { this.timer = setInterval(() => { this.lastRequestTimestamp = Date.now() this.makeRequests() - }, constants.REQUESTS_INTERVAL) + }, this.requestInterval) } deactivate () { @@ -41,6 +41,10 @@ module.exports = class BaseRequestScheduler { return constants.REQUESTS_INTERVAL - (Date.now() - this.lastRequestTimestamp) } + remainingRequestsCount (callback) { + return this.getRequestModel().countTotalRequests(callback) + } + // --------------------------------------------------------------------------- // Make a requests to friends of a certain type @@ -95,14 +99,6 @@ module.exports = class BaseRequestScheduler { const requestToMake = requestsToMakeGrouped[hashKey] const toPod = requestToMake.toPod - // Maybe the pod is not our friend anymore so simply remove it - if (!toPod) { - const requestIdsToDelete = requestToMake.ids - - logger.info('Removing %d "%s" of unexisting pod %s.', requestIdsToDelete.length, this.description, requestToMake.toPod.id) - return this.getRequestToPodModel().removePodOf(requestIdsToDelete, requestToMake.toPod.id, callbackEach) - } - this.makeRequest(toPod, requestToMake.endpoint, requestToMake.datas, (success) => { if (success === false) { badPods.push(requestToMake.toPod.id)