diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-06-25 17:19:46 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-06-25 17:19:46 +0200 |
commit | e636eb88101a51399057c86477af6677f5614d48 (patch) | |
tree | ba56f0da932613c8013a2c52905ded1987cd6d6d /server/controllers/api/request-schedulers.ts | |
parent | 4f133041819409a72cf70fa2fa6c4df14c6de4fd (diff) | |
download | PeerTube-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.ts | 59 |
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 @@ | |||
1 | import * as express from 'express' | ||
2 | import { parallel } from 'async' | ||
3 | |||
4 | import { | ||
5 | AbstractRequestScheduler, | ||
6 | getRequestScheduler, | ||
7 | getRequestVideoQaduScheduler, | ||
8 | getRequestVideoEventScheduler | ||
9 | } from '../../lib' | ||
10 | import { authenticate, ensureIsAdmin } from '../../middlewares' | ||
11 | import { RequestSchedulerStatsAttributes } from '../../../shared' | ||
12 | |||
13 | const requestSchedulerRouter = express.Router() | ||
14 | |||
15 | requestSchedulerRouter.get('/stats', | ||
16 | authenticate, | ||
17 | ensureIsAdmin, | ||
18 | getRequestSchedulersStats | ||
19 | ) | ||
20 | |||
21 | // --------------------------------------------------------------------------- | ||
22 | |||
23 | export { | ||
24 | requestSchedulerRouter | ||
25 | } | ||
26 | |||
27 | // --------------------------------------------------------------------------- | ||
28 | |||
29 | function 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 | |||
43 | function 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 | } | ||