const requests = require('../helpers/requests')
module.exports = class BaseRequestScheduler {
-
constructor (options) {
this.lastRequestTimestamp = 0
this.timer = null
+ this.requestInterval = constants.REQUESTS_INTERVAL
}
activate () {
this.timer = setInterval(() => {
this.lastRequestTimestamp = Date.now()
this.makeRequests()
- }, constants.REQUESTS_INTERVAL)
+ }, this.requestInterval)
}
deactivate () {
return constants.REQUESTS_INTERVAL - (Date.now() - this.lastRequestTimestamp)
}
+ remainingRequestsCount (callback) {
+ return this.getRequestModel().countTotalRequests(callback)
+ }
+
// ---------------------------------------------------------------------------
// Make a requests to friends of a certain type
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)