aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/requests.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api/requests.js')
-rw-r--r--server/controllers/api/requests.js37
1 files changed, 28 insertions, 9 deletions
diff --git a/server/controllers/api/requests.js b/server/controllers/api/requests.js
index 3e0d246d1..be352113e 100644
--- a/server/controllers/api/requests.js
+++ b/server/controllers/api/requests.js
@@ -1,9 +1,10 @@
1'use strict' 1'use strict'
2 2
3const express = require('express') 3const express = require('express')
4const parallel = require('async/parallel')
4 5
5const constants = require('../../initializers/constants') 6const constants = require('../../initializers/constants')
6const db = require('../../initializers/database') 7const friends = require('../../lib/friends')
7const middlewares = require('../../middlewares') 8const middlewares = require('../../middlewares')
8const admin = middlewares.admin 9const admin = middlewares.admin
9const oAuth = middlewares.oauth 10const oAuth = middlewares.oauth
@@ -23,15 +24,33 @@ module.exports = router
23// --------------------------------------------------------------------------- 24// ---------------------------------------------------------------------------
24 25
25function getStatsRequests (req, res, next) { 26function getStatsRequests (req, res, next) {
26 db.Request.countTotalRequests(function (err, totalRequests) { 27 parallel({
28 requestScheduler: buildRequestSchedulerFunction(friends.getRequestScheduler()),
29 requestVideoQaduScheduler: buildRequestSchedulerFunction(friends.getRequestVideoQaduScheduler()),
30 requestVideoEventScheduler: buildRequestSchedulerFunction(friends.getRequestVideoEventScheduler())
31 }, function (err, result) {
27 if (err) return next(err) 32 if (err) return next(err)
28 33
29 return res.json({ 34 return res.json(result)
30 totalRequests: totalRequests,
31 requestsLimitPods: constants.REQUESTS_LIMIT_PODS,
32 requestsLimitPerPod: constants.REQUESTS_LIMIT_PER_POD,
33 remainingMilliSeconds: db.Request.remainingMilliSeconds(),
34 milliSecondsInterval: constants.REQUESTS_INTERVAL
35 })
36 }) 35 })
37} 36}
37
38// ---------------------------------------------------------------------------
39
40function buildRequestSchedulerFunction (requestScheduler) {
41 return function (callback) {
42 requestScheduler.remainingRequestsCount(function (err, count) {
43 if (err) return callback(err)
44
45 const result = {
46 totalRequests: count,
47 requestsLimitPods: requestScheduler.limitPods,
48 requestsLimitPerPod: requestScheduler.limitPerPod,
49 remainingMilliSeconds: requestScheduler.remainingMilliSeconds(),
50 milliSecondsInterval: requestScheduler.requestInterval
51 }
52
53 return callback(null, result)
54 })
55 }
56}