1
0
Fork 0
peertube/server/controllers/api/requests.js

56 lines
1.6 KiB
JavaScript
Raw Normal View History

2016-09-19 15:33:46 -04:00
'use strict'
const express = require('express')
2017-02-27 15:56:55 -05:00
const parallel = require('async/parallel')
2016-09-19 15:33:46 -04:00
2017-02-27 15:56:55 -05:00
const friends = require('../../lib/friends')
const middlewares = require('../../middlewares')
2016-09-19 15:33:46 -04:00
const admin = middlewares.admin
const oAuth = middlewares.oauth
const router = express.Router()
router.get('/stats',
oAuth.authenticate,
admin.ensureIsAdmin,
getStatsRequests
)
// ---------------------------------------------------------------------------
module.exports = router
// ---------------------------------------------------------------------------
function getStatsRequests (req, res, next) {
2017-02-27 15:56:55 -05:00
parallel({
requestScheduler: buildRequestSchedulerFunction(friends.getRequestScheduler()),
requestVideoQaduScheduler: buildRequestSchedulerFunction(friends.getRequestVideoQaduScheduler()),
requestVideoEventScheduler: buildRequestSchedulerFunction(friends.getRequestVideoEventScheduler())
}, function (err, result) {
2016-09-19 15:33:46 -04:00
if (err) return next(err)
2017-02-27 15:56:55 -05:00
return res.json(result)
2016-09-19 15:33:46 -04:00
})
}
2017-02-27 15:56:55 -05:00
// ---------------------------------------------------------------------------
function buildRequestSchedulerFunction (requestScheduler) {
return function (callback) {
requestScheduler.remainingRequestsCount(function (err, count) {
if (err) return callback(err)
const result = {
totalRequests: count,
requestsLimitPods: requestScheduler.limitPods,
requestsLimitPerPod: requestScheduler.limitPerPod,
remainingMilliSeconds: requestScheduler.remainingMilliSeconds(),
milliSecondsInterval: requestScheduler.requestInterval
}
return callback(null, result)
})
}
}