aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/lib/requestsScheduler.js70
1 files changed, 48 insertions, 22 deletions
diff --git a/server/lib/requestsScheduler.js b/server/lib/requestsScheduler.js
index f10de6276..3d04b8cc8 100644
--- a/server/lib/requestsScheduler.js
+++ b/server/lib/requestsScheduler.js
@@ -177,35 +177,61 @@ function makeRequests () {
177} 177}
178 178
179function removeBadPods () { 179function removeBadPods () {
180 Pods.findBadPods(function (err, pods) { 180 async.waterfall([
181 if (err) { 181 function findBadPods (callback) {
182 logger.error('Cannot find bad pods.', { error: err }) 182 Pods.findBadPods(function (err, pods) {
183 return // abort 183 if (err) {
184 } 184 logger.error('Cannot find bad pods.', { error: err })
185 return callback(err)
186 }
185 187
186 if (pods.length === 0) return 188 return callback(null, pods)
189 })
190 },
187 191
188 const urls = map(pods, 'url') 192 function listVideosOfTheseBadPods (pods, callback) {
189 const ids = map(pods, '_id') 193 if (pods.length === 0) return callback(null)
190 194
191 Videos.listFromUrls(urls, function (err, videosList) { 195 const urls = map(pods, 'url')
192 if (err) { 196 const ids = map(pods, '_id')
193 logger.error('Cannot list videos urls.', { error: err, urls: urls })
194 } else {
195 videos.removeRemoteVideos(videosList, function (err) {
196 if (err) logger.error('Cannot remove remote videos.', { error: err })
197 })
198 }
199 197
200 Pods.removeAllByIds(ids, function (err, r) { 198 Videos.listFromUrls(urls, function (err, videosList) {
201 if (err) { 199 if (err) {
202 logger.error('Cannot remove bad pods.', { error: err }) 200 logger.error('Cannot list videos urls.', { error: err, urls: urls })
203 } else { 201 return callback(null, ids, [])
204 const podsRemoved = r.result.n
205 logger.info('Removed %d pods.', podsRemoved)
206 } 202 }
203
204 return callback(null, ids, videosList)
207 }) 205 })
208 }) 206 },
207
208 function removeVideosOfTheseBadPods (podIds, videosList, callback) {
209 // We don't have to remove pods, skip
210 if (typeof podIds === 'function') return podIds(null)
211
212 // Remove the remote videos
213 videos.removeRemoteVideos(videosList, function (err) {
214 if (err) logger.error('Cannot remove remote videos.', { error: err })
215
216 return callback(null, podIds)
217 })
218 },
219
220 function removeBadPodsFromDB (podIds, callback) {
221 // We don't have to remove pods, skip
222 if (typeof podIds === 'function') return podIds(null)
223
224 Pods.removeAllByIds(podIds, callback)
225 }
226 ], function (err, removeResult) {
227 if (err) {
228 logger.error('Cannot remove bad pods.', { error: err })
229 } else if (removeResult) {
230 const podsRemoved = removeResult.result.n
231 logger.info('Removed %d pods.', podsRemoved)
232 } else {
233 logger.info('No need to remove bad pods.')
234 }
209 }) 235 })
210} 236}
211 237