diff options
Diffstat (limited to 'server/controllers/api')
-rw-r--r-- | server/controllers/api/requests.js | 37 |
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 | ||
3 | const express = require('express') | 3 | const express = require('express') |
4 | const parallel = require('async/parallel') | ||
4 | 5 | ||
5 | const constants = require('../../initializers/constants') | 6 | const constants = require('../../initializers/constants') |
6 | const db = require('../../initializers/database') | 7 | const friends = require('../../lib/friends') |
7 | const middlewares = require('../../middlewares') | 8 | const middlewares = require('../../middlewares') |
8 | const admin = middlewares.admin | 9 | const admin = middlewares.admin |
9 | const oAuth = middlewares.oauth | 10 | const oAuth = middlewares.oauth |
@@ -23,15 +24,33 @@ module.exports = router | |||
23 | // --------------------------------------------------------------------------- | 24 | // --------------------------------------------------------------------------- |
24 | 25 | ||
25 | function getStatsRequests (req, res, next) { | 26 | function 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 | |||
40 | function 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 | } | ||