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