]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/base-request-scheduler.js
Update bittorrent-tracker and standard to v9
[github/Chocobozzz/PeerTube.git] / server / lib / base-request-scheduler.js
index d15680c25a5789b227e29eb56b5e8eaa120e148e..4709c7960fee4c97b05c0e377b1ee11e81b3be06 100644 (file)
@@ -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)