aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/request-schedulers.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-10-25 11:55:06 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-10-26 09:11:38 +0200
commiteb08047657e739bcd9e592d76307befa3998482b (patch)
treefc309f51ece792fd4307c4af510710a853e1d6b2 /server/controllers/api/request-schedulers.ts
parent5f04dd2f743961e0a06c29531cc3ccc9e4928d56 (diff)
downloadPeerTube-eb08047657e739bcd9e592d76307befa3998482b.tar.gz
PeerTube-eb08047657e739bcd9e592d76307befa3998482b.tar.zst
PeerTube-eb08047657e739bcd9e592d76307befa3998482b.zip
Use async/await in controllers
Diffstat (limited to 'server/controllers/api/request-schedulers.ts')
-rw-r--r--server/controllers/api/request-schedulers.ts38
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 @@
1import * as express from 'express' 1import * as express from 'express'
2import * as Promise from 'bluebird' 2import * as Bluebird from 'bluebird'
3 3
4import { 4import {
5 AbstractRequestScheduler, 5 AbstractRequestScheduler,
@@ -7,7 +7,7 @@ import {
7 getRequestVideoQaduScheduler, 7 getRequestVideoQaduScheduler,
8 getRequestVideoEventScheduler 8 getRequestVideoEventScheduler
9} from '../../lib' 9} from '../../lib'
10import { authenticate, ensureIsAdmin } from '../../middlewares' 10import { authenticate, ensureIsAdmin, asyncMiddleware } from '../../middlewares'
11import { RequestSchedulerStatsAttributes } from '../../../shared' 11import { RequestSchedulerStatsAttributes } from '../../../shared'
12 12
13const requestSchedulerRouter = express.Router() 13const requestSchedulerRouter = express.Router()
@@ -15,7 +15,7 @@ const requestSchedulerRouter = express.Router()
15requestSchedulerRouter.get('/stats', 15requestSchedulerRouter.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
29function getRequestSchedulersStats (req: express.Request, res: express.Response, next: express.NextFunction) { 29async 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
41function buildRequestSchedulerStats (requestScheduler: AbstractRequestScheduler<any>) { 41async 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}