aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/request-schedulers.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-07-05 13:26:25 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-07-05 14:14:16 +0200
commit6fcd19ba737f1f5614a56c6925adb882dea43b8d (patch)
tree3365a96d82bc7f00ae504a568725c8e914150cf8 /server/controllers/api/request-schedulers.ts
parent5fe7e898316e18369c3e1aba307b55077adc7bfb (diff)
downloadPeerTube-6fcd19ba737f1f5614a56c6925adb882dea43b8d.tar.gz
PeerTube-6fcd19ba737f1f5614a56c6925adb882dea43b8d.tar.zst
PeerTube-6fcd19ba737f1f5614a56c6925adb882dea43b8d.zip
Move to promises
Closes https://github.com/Chocobozzz/PeerTube/issues/74
Diffstat (limited to 'server/controllers/api/request-schedulers.ts')
-rw-r--r--server/controllers/api/request-schedulers.ts38
1 files changed, 16 insertions, 22 deletions
diff --git a/server/controllers/api/request-schedulers.ts b/server/controllers/api/request-schedulers.ts
index 8dd849007..2a934a512 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 { parallel } from 'async' 2import * as Promise from 'bluebird'
3 3
4import { 4import {
5 AbstractRequestScheduler, 5 AbstractRequestScheduler,
@@ -27,33 +27,27 @@ export {
27// --------------------------------------------------------------------------- 27// ---------------------------------------------------------------------------
28 28
29function getRequestSchedulersStats (req: express.Request, res: express.Response, next: express.NextFunction) { 29function getRequestSchedulersStats (req: express.Request, res: express.Response, next: express.NextFunction) {
30 parallel({ 30 Promise.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 }, function (err, result) {
35 if (err) return next(err)
36
37 return res.json(result)
38 }) 34 })
35 .then(result => res.json(result))
36 .catch(err => next(err))
39} 37}
40 38
41// --------------------------------------------------------------------------- 39// ---------------------------------------------------------------------------
42 40
43function buildRequestSchedulerStats (requestScheduler: AbstractRequestScheduler) { 41function buildRequestSchedulerStats (requestScheduler: AbstractRequestScheduler<any>) {
44 return function (callback) { 42 return requestScheduler.remainingRequestsCount().then(count => {
45 requestScheduler.remainingRequestsCount(function (err, count) { 43 const result: RequestSchedulerStatsAttributes = {
46 if (err) return callback(err) 44 totalRequests: count,
47 45 requestsLimitPods: requestScheduler.limitPods,
48 const result: RequestSchedulerStatsAttributes = { 46 requestsLimitPerPod: requestScheduler.limitPerPod,
49 totalRequests: count, 47 remainingMilliSeconds: requestScheduler.remainingMilliSeconds(),
50 requestsLimitPods: requestScheduler.limitPods, 48 milliSecondsInterval: requestScheduler.requestInterval
51 requestsLimitPerPod: requestScheduler.limitPerPod, 49 }
52 remainingMilliSeconds: requestScheduler.remainingMilliSeconds(), 50
53 milliSecondsInterval: requestScheduler.requestInterval 51 return result
54 } 52 })
55
56 return callback(null, result)
57 })
58 }
59} 53}