aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/requests.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api/requests.ts')
-rw-r--r--server/controllers/api/requests.ts57
1 files changed, 57 insertions, 0 deletions
diff --git a/server/controllers/api/requests.ts b/server/controllers/api/requests.ts
new file mode 100644
index 000000000..304499a4f
--- /dev/null
+++ b/server/controllers/api/requests.ts
@@ -0,0 +1,57 @@
1import express = require('express')
2import { parallel } from 'async'
3
4import {
5 getRequestScheduler,
6 getRequestVideoQaduScheduler,
7 getRequestVideoEventScheduler
8} from '../../lib'
9import { authenticate, ensureIsAdmin } from '../../middlewares'
10
11const requestsRouter = express.Router()
12
13requestsRouter.get('/stats',
14 authenticate,
15 ensureIsAdmin,
16 getStatsRequests
17)
18
19// ---------------------------------------------------------------------------
20
21export {
22 requestsRouter
23}
24
25// ---------------------------------------------------------------------------
26
27function getStatsRequests (req, res, next) {
28 parallel({
29 requestScheduler: buildRequestSchedulerFunction(getRequestScheduler()),
30 requestVideoQaduScheduler: buildRequestSchedulerFunction(getRequestVideoQaduScheduler()),
31 requestVideoEventScheduler: buildRequestSchedulerFunction(getRequestVideoEventScheduler())
32 }, function (err, result) {
33 if (err) return next(err)
34
35 return res.json(result)
36 })
37}
38
39// ---------------------------------------------------------------------------
40
41function buildRequestSchedulerFunction (requestScheduler) {
42 return function (callback) {
43 requestScheduler.remainingRequestsCount(function (err, count) {
44 if (err) return callback(err)
45
46 const result = {
47 totalRequests: count,
48 requestsLimitPods: requestScheduler.limitPods,
49 requestsLimitPerPod: requestScheduler.limitPerPod,
50 remainingMilliSeconds: requestScheduler.remainingMilliSeconds(),
51 milliSecondsInterval: requestScheduler.requestInterval
52 }
53
54 return callback(null, result)
55 })
56 }
57}