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