aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-02-27 21:56:55 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-02-27 21:56:55 +0100
commit99fdec464802e5d720fe08ead06b63368b115baf (patch)
treed3129ec4e37894036fc8e83ee17a953873f41e12 /server/lib
parent05a9feaa48cea560abd9561434a3479ab1021643 (diff)
downloadPeerTube-99fdec464802e5d720fe08ead06b63368b115baf.tar.gz
PeerTube-99fdec464802e5d720fe08ead06b63368b115baf.tar.zst
PeerTube-99fdec464802e5d720fe08ead06b63368b115baf.zip
Fix request schedulers stats
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/base-request-scheduler.js7
-rw-r--r--server/lib/friends.js31
2 files changed, 29 insertions, 9 deletions
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 {
12 constructor (options) { 12 constructor (options) {
13 this.lastRequestTimestamp = 0 13 this.lastRequestTimestamp = 0
14 this.timer = null 14 this.timer = null
15 this.requestInterval = constants.REQUESTS_INTERVAL
15 } 16 }
16 17
17 activate () { 18 activate () {
@@ -21,7 +22,7 @@ module.exports = class BaseRequestScheduler {
21 this.timer = setInterval(() => { 22 this.timer = setInterval(() => {
22 this.lastRequestTimestamp = Date.now() 23 this.lastRequestTimestamp = Date.now()
23 this.makeRequests() 24 this.makeRequests()
24 }, constants.REQUESTS_INTERVAL) 25 }, this.requestInterval)
25 } 26 }
26 27
27 deactivate () { 28 deactivate () {
@@ -41,6 +42,10 @@ module.exports = class BaseRequestScheduler {
41 return constants.REQUESTS_INTERVAL - (Date.now() - this.lastRequestTimestamp) 42 return constants.REQUESTS_INTERVAL - (Date.now() - this.lastRequestTimestamp)
42 } 43 }
43 44
45 remainingRequestsCount (callback) {
46 return this.getRequestModel().countTotalRequests(callback)
47 }
48
44 // --------------------------------------------------------------------------- 49 // ---------------------------------------------------------------------------
45 50
46 // Make a requests to friends of a certain type 51 // 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')
19const ENDPOINT_ACTIONS = constants.REQUEST_ENDPOINT_ACTIONS[constants.REQUEST_ENDPOINTS.VIDEOS] 19const ENDPOINT_ACTIONS = constants.REQUEST_ENDPOINT_ACTIONS[constants.REQUEST_ENDPOINTS.VIDEOS]
20 20
21const requestScheduler = new RequestScheduler() 21const requestScheduler = new RequestScheduler()
22const requestSchedulerVideoQadu = new RequestVideoQaduScheduler() 22const requestVideoQaduScheduler = new RequestVideoQaduScheduler()
23const requestSchedulerVideoEvent = new RequestVideoEventScheduler() 23const requestVideoEventScheduler = new RequestVideoEventScheduler()
24 24
25const friends = { 25const friends = {
26 activate, 26 activate,
@@ -33,13 +33,16 @@ const friends = {
33 makeFriends, 33 makeFriends,
34 quitFriends, 34 quitFriends,
35 removeVideoToFriends, 35 removeVideoToFriends,
36 sendOwnedVideosToPod 36 sendOwnedVideosToPod,
37 getRequestScheduler,
38 getRequestVideoQaduScheduler,
39 getRequestVideoEventScheduler
37} 40}
38 41
39function activate () { 42function activate () {
40 requestScheduler.activate() 43 requestScheduler.activate()
41 requestSchedulerVideoQadu.activate() 44 requestVideoQaduScheduler.activate()
42 requestSchedulerVideoEvent.activate() 45 requestVideoEventScheduler.activate()
43} 46}
44 47
45function addVideoToFriends (videoData, transaction, callback) { 48function addVideoToFriends (videoData, transaction, callback) {
@@ -142,7 +145,7 @@ function quitFriends (callback) {
142 }, 145 },
143 146
144 function flushVideoQaduRequests (callbackAsync) { 147 function flushVideoQaduRequests (callbackAsync) {
145 requestSchedulerVideoQadu.flush(err => callbackAsync(err)) 148 requestVideoQaduScheduler.flush(err => callbackAsync(err))
146 }, 149 },
147 150
148 function getPodsList (callbackAsync) { 151 function getPodsList (callbackAsync) {
@@ -215,6 +218,18 @@ function sendOwnedVideosToPod (podId) {
215 }) 218 })
216} 219}
217 220
221function getRequestScheduler () {
222 return requestScheduler
223}
224
225function getRequestVideoQaduScheduler () {
226 return requestVideoQaduScheduler
227}
228
229function getRequestVideoEventScheduler () {
230 return requestVideoEventScheduler
231}
232
218// --------------------------------------------------------------------------- 233// ---------------------------------------------------------------------------
219 234
220module.exports = friends 235module.exports = friends
@@ -345,13 +360,13 @@ function createRequest (options, callback) {
345function createVideoQaduRequest (options, callback) { 360function createVideoQaduRequest (options, callback) {
346 if (!callback) callback = utils.createEmptyCallback() 361 if (!callback) callback = utils.createEmptyCallback()
347 362
348 requestSchedulerVideoQadu.createRequest(options, callback) 363 requestVideoQaduScheduler.createRequest(options, callback)
349} 364}
350 365
351function createVideoEventRequest (options, callback) { 366function createVideoEventRequest (options, callback) {
352 if (!callback) callback = utils.createEmptyCallback() 367 if (!callback) callback = utils.createEmptyCallback()
353 368
354 requestSchedulerVideoEvent.createRequest(options, callback) 369 requestVideoEventScheduler.createRequest(options, callback)
355} 370}
356 371
357function isMe (host) { 372function isMe (host) {