diff options
Diffstat (limited to 'server/controllers/api/request-schedulers.ts')
-rw-r--r-- | server/controllers/api/request-schedulers.ts | 53 |
1 files changed, 0 insertions, 53 deletions
diff --git a/server/controllers/api/request-schedulers.ts b/server/controllers/api/request-schedulers.ts deleted file mode 100644 index 4c8fbe18b..000000000 --- a/server/controllers/api/request-schedulers.ts +++ /dev/null | |||
@@ -1,53 +0,0 @@ | |||
1 | import * as express from 'express' | ||
2 | import * as Bluebird from 'bluebird' | ||
3 | |||
4 | import { | ||
5 | AbstractRequestScheduler, | ||
6 | getRequestScheduler, | ||
7 | getRequestVideoQaduScheduler, | ||
8 | getRequestVideoEventScheduler | ||
9 | } from '../../lib' | ||
10 | import { authenticate, ensureUserHasRight, asyncMiddleware } from '../../middlewares' | ||
11 | import { RequestSchedulerStatsAttributes, UserRight } from '../../../shared' | ||
12 | |||
13 | const requestSchedulerRouter = express.Router() | ||
14 | |||
15 | requestSchedulerRouter.get('/stats', | ||
16 | authenticate, | ||
17 | ensureUserHasRight(UserRight.MANAGE_REQUEST_SCHEDULERS), | ||
18 | asyncMiddleware(getRequestSchedulersStats) | ||
19 | ) | ||
20 | |||
21 | // --------------------------------------------------------------------------- | ||
22 | |||
23 | export { | ||
24 | requestSchedulerRouter | ||
25 | } | ||
26 | |||
27 | // --------------------------------------------------------------------------- | ||
28 | |||
29 | async function getRequestSchedulersStats (req: express.Request, res: express.Response, next: express.NextFunction) { | ||
30 | const result = await Bluebird.props({ | ||
31 | requestScheduler: buildRequestSchedulerStats(getRequestScheduler()), | ||
32 | requestVideoQaduScheduler: buildRequestSchedulerStats(getRequestVideoQaduScheduler()), | ||
33 | requestVideoEventScheduler: buildRequestSchedulerStats(getRequestVideoEventScheduler()) | ||
34 | }) | ||
35 | |||
36 | return res.json(result) | ||
37 | } | ||
38 | |||
39 | // --------------------------------------------------------------------------- | ||
40 | |||
41 | async function buildRequestSchedulerStats (requestScheduler: AbstractRequestScheduler<any>) { | ||
42 | const count = await requestScheduler.remainingRequestsCount() | ||
43 | |||
44 | const result: RequestSchedulerStatsAttributes = { | ||
45 | totalRequests: count, | ||
46 | requestsLimitPods: requestScheduler.limitPods, | ||
47 | requestsLimitPerPod: requestScheduler.limitPerPod, | ||
48 | remainingMilliSeconds: requestScheduler.remainingMilliSeconds(), | ||
49 | milliSecondsInterval: requestScheduler.requestInterval | ||
50 | } | ||
51 | |||
52 | return result | ||
53 | } | ||