-// Remove pods with a score of 0 (too many requests where they were unreachable)
-function removeBadPods () {
- async.waterfall([
- function findBadPods (callback) {
- Pod.listBadPods(function (err, pods) {
- if (err) {
- logger.error('Cannot find bad pods.', { error: err })
- return callback(err)
- }
-
- return callback(null, pods)
- })
- },
-
- function listVideosOfTheseBadPods (pods, callback) {
- if (pods.length === 0) return callback(null)
-
- const urls = map(pods, 'url')
-
- Video.listByUrls(urls, function (err, videosList) {
- if (err) {
- logger.error('Cannot list videos urls.', { error: err, urls: urls })
- return callback(null, pods, [])
- }
-
- return callback(null, pods, videosList)
- })
- },
-
- function removeVideosOfTheseBadPods (pods, videosList, callback) {
- // We don't have to remove pods, skip
- if (typeof pods === 'function') {
- callback = pods
- return callback(null)
- }
-
- async.each(videosList, function (video, callbackEach) {
- video.remove(callbackEach)
- }, function (err) {
- if (err) {
- // Don't stop the process
- logger.error('Error while removing videos of bad pods.', { error: err })
- return
- }