diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-05-15 22:22:03 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-05-20 09:57:40 +0200 |
commit | 65fcc3119c334b75dd13bcfdebf186afdc580a8f (patch) | |
tree | 4f2158c61a9b7c3f47cfa233d01413b946ee53c0 /server/controllers/api/requests.ts | |
parent | d5f345ed4cfac4e1fa84dcb4fce1cda4d32f9c73 (diff) | |
download | PeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.tar.gz PeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.tar.zst PeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.zip |
First typescript iteration
Diffstat (limited to 'server/controllers/api/requests.ts')
-rw-r--r-- | server/controllers/api/requests.ts | 57 |
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 @@ | |||
1 | import express = require('express') | ||
2 | import { parallel } from 'async' | ||
3 | |||
4 | import { | ||
5 | getRequestScheduler, | ||
6 | getRequestVideoQaduScheduler, | ||
7 | getRequestVideoEventScheduler | ||
8 | } from '../../lib' | ||
9 | import { authenticate, ensureIsAdmin } from '../../middlewares' | ||
10 | |||
11 | const requestsRouter = express.Router() | ||
12 | |||
13 | requestsRouter.get('/stats', | ||
14 | authenticate, | ||
15 | ensureIsAdmin, | ||
16 | getStatsRequests | ||
17 | ) | ||
18 | |||
19 | // --------------------------------------------------------------------------- | ||
20 | |||
21 | export { | ||
22 | requestsRouter | ||
23 | } | ||
24 | |||
25 | // --------------------------------------------------------------------------- | ||
26 | |||
27 | function 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 | |||
41 | function 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 | } | ||