aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/request-schedulers.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-06-25 17:19:46 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-06-25 17:19:46 +0200
commite636eb88101a51399057c86477af6677f5614d48 (patch)
treeba56f0da932613c8013a2c52905ded1987cd6d6d /server/controllers/api/request-schedulers.ts
parent4f133041819409a72cf70fa2fa6c4df14c6de4fd (diff)
downloadPeerTube-e636eb88101a51399057c86477af6677f5614d48.tar.gz
PeerTube-e636eb88101a51399057c86477af6677f5614d48.tar.zst
PeerTube-e636eb88101a51399057c86477af6677f5614d48.zip
Requests -> RequestSchedulers
Diffstat (limited to 'server/controllers/api/request-schedulers.ts')
-rw-r--r--server/controllers/api/request-schedulers.ts59
1 files changed, 59 insertions, 0 deletions
diff --git a/server/controllers/api/request-schedulers.ts b/server/controllers/api/request-schedulers.ts
new file mode 100644
index 000000000..8dd849007
--- /dev/null
+++ b/server/controllers/api/request-schedulers.ts
@@ -0,0 +1,59 @@
1import * as express from 'express'
2import { parallel } from 'async'
3
4import {
5 AbstractRequestScheduler,
6 getRequestScheduler,
7 getRequestVideoQaduScheduler,
8 getRequestVideoEventScheduler
9} from '../../lib'
10import { authenticate, ensureIsAdmin } from '../../middlewares'
11import { RequestSchedulerStatsAttributes } from '../../../shared'
12
13const requestSchedulerRouter = express.Router()
14
15requestSchedulerRouter.get('/stats',
16 authenticate,
17 ensureIsAdmin,
18 getRequestSchedulersStats
19)
20
21// ---------------------------------------------------------------------------
22
23export {
24 requestSchedulerRouter
25}
26
27// ---------------------------------------------------------------------------
28
29function getRequestSchedulersStats (req: express.Request, res: express.Response, next: express.NextFunction) {
30 parallel({
31 requestScheduler: buildRequestSchedulerStats(getRequestScheduler()),
32 requestVideoQaduScheduler: buildRequestSchedulerStats(getRequestVideoQaduScheduler()),
33 requestVideoEventScheduler: buildRequestSchedulerStats(getRequestVideoEventScheduler())
34 }, function (err, result) {
35 if (err) return next(err)
36
37 return res.json(result)
38 })
39}
40
41// ---------------------------------------------------------------------------
42
43function buildRequestSchedulerStats (requestScheduler: AbstractRequestScheduler) {
44 return function (callback) {
45 requestScheduler.remainingRequestsCount(function (err, count) {
46 if (err) return callback(err)
47
48 const result: RequestSchedulerStatsAttributes = {
49 totalRequests: count,
50 requestsLimitPods: requestScheduler.limitPods,
51 requestsLimitPerPod: requestScheduler.limitPerPod,
52 remainingMilliSeconds: requestScheduler.remainingMilliSeconds(),
53 milliSecondsInterval: requestScheduler.requestInterval
54 }
55
56 return callback(null, result)
57 })
58 }
59}