From 99fdec464802e5d720fe08ead06b63368b115baf Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 27 Feb 2017 21:56:55 +0100 Subject: Fix request schedulers stats --- server/lib/base-request-scheduler.js | 7 ++++++- server/lib/friends.js | 31 +++++++++++++++++++++++-------- 2 files changed, 29 insertions(+), 9 deletions(-) (limited to 'server/lib') diff --git a/server/lib/base-request-scheduler.js b/server/lib/base-request-scheduler.js index 309c1a261..1c6b78297 100644 --- a/server/lib/base-request-scheduler.js +++ b/server/lib/base-request-scheduler.js @@ -12,6 +12,7 @@ module.exports = class BaseRequestScheduler { constructor (options) { this.lastRequestTimestamp = 0 this.timer = null + this.requestInterval = constants.REQUESTS_INTERVAL } activate () { @@ -21,7 +22,7 @@ module.exports = class BaseRequestScheduler { this.timer = setInterval(() => { this.lastRequestTimestamp = Date.now() this.makeRequests() - }, constants.REQUESTS_INTERVAL) + }, this.requestInterval) } deactivate () { @@ -41,6 +42,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 diff --git a/server/lib/friends.js b/server/lib/friends.js index 203f0e52c..7bd087d8c 100644 --- a/server/lib/friends.js +++ b/server/lib/friends.js @@ -19,8 +19,8 @@ const RequestVideoEventScheduler = require('./request-video-event-scheduler') const ENDPOINT_ACTIONS = constants.REQUEST_ENDPOINT_ACTIONS[constants.REQUEST_ENDPOINTS.VIDEOS] const requestScheduler = new RequestScheduler() -const requestSchedulerVideoQadu = new RequestVideoQaduScheduler() -const requestSchedulerVideoEvent = new RequestVideoEventScheduler() +const requestVideoQaduScheduler = new RequestVideoQaduScheduler() +const requestVideoEventScheduler = new RequestVideoEventScheduler() const friends = { activate, @@ -33,13 +33,16 @@ const friends = { makeFriends, quitFriends, removeVideoToFriends, - sendOwnedVideosToPod + sendOwnedVideosToPod, + getRequestScheduler, + getRequestVideoQaduScheduler, + getRequestVideoEventScheduler } function activate () { requestScheduler.activate() - requestSchedulerVideoQadu.activate() - requestSchedulerVideoEvent.activate() + requestVideoQaduScheduler.activate() + requestVideoEventScheduler.activate() } function addVideoToFriends (videoData, transaction, callback) { @@ -142,7 +145,7 @@ function quitFriends (callback) { }, function flushVideoQaduRequests (callbackAsync) { - requestSchedulerVideoQadu.flush(err => callbackAsync(err)) + requestVideoQaduScheduler.flush(err => callbackAsync(err)) }, function getPodsList (callbackAsync) { @@ -215,6 +218,18 @@ function sendOwnedVideosToPod (podId) { }) } +function getRequestScheduler () { + return requestScheduler +} + +function getRequestVideoQaduScheduler () { + return requestVideoQaduScheduler +} + +function getRequestVideoEventScheduler () { + return requestVideoEventScheduler +} + // --------------------------------------------------------------------------- module.exports = friends @@ -345,13 +360,13 @@ function createRequest (options, callback) { function createVideoQaduRequest (options, callback) { if (!callback) callback = utils.createEmptyCallback() - requestSchedulerVideoQadu.createRequest(options, callback) + requestVideoQaduScheduler.createRequest(options, callback) } function createVideoEventRequest (options, callback) { if (!callback) callback = utils.createEmptyCallback() - requestSchedulerVideoEvent.createRequest(options, callback) + requestVideoEventScheduler.createRequest(options, callback) } function isMe (host) { -- cgit v1.2.3