const Video = mongoose.model('Video')
let timer = null
+let lastRequestTimestamp = 0
// ---------------------------------------------------------------------------
deactivate,
flush,
forceSend,
- list
+ list,
+ remainingMilliSeconds
}
RequestSchema.pre('save', function (next) {
function activate () {
logger.info('Requests scheduler activated.')
- timer = setInterval(makeRequests.bind(this), constants.REQUESTS_INTERVAL)
+ lastRequestTimestamp = Date.now()
+
+ const self = this
+ timer = setInterval(function () {
+ lastRequestTimestamp = Date.now()
+ makeRequests.call(self)
+ }, constants.REQUESTS_INTERVAL)
}
function deactivate () {
logger.info('Requests scheduler deactivated.')
clearInterval(timer)
+ timer = null
}
function flush () {
this.find({ }, callback)
}
+function remainingMilliSeconds () {
+ if (timer === null) return -1
+
+ return constants.REQUESTS_INTERVAL - (Date.now() - lastRequestTimestamp)
+}
+
// ---------------------------------------------------------------------------
// Make a requests to friends of a certain type
'Error sending secure request to %s pod.',
toPod.url,
{
- error: err || new Error('Status code not 20x'),
- statusCode: res.statusCode
+ error: err || new Error('Status code not 20x : ' + res.statusCode)
}
)
return callbackEach()
}
- // Maybe the pod is not our friend anymore so simply remove them
+ // Maybe the pod is not our friend anymore so simply remove it
if (!toPod) {
+ logger.info('Removing %d requests of unexisting pod %s.', requestToMake.ids.length, toPodId)
removePodOf.call(self, requestToMake.ids, toPodId)
return callbackEach()
}