aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/request.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-10-21 11:20:45 +0200
committerChocobozzz <florian.bigard@gmail.com>2016-10-21 11:20:45 +0200
commit80a6c9e76fda57f01e37fe4620771ae70738a211 (patch)
tree7381a94285c11d954efca2be8103c8b86df3e832 /server/models/request.js
parent792b893ed414301c060391ed8a00368d68688236 (diff)
downloadPeerTube-80a6c9e76fda57f01e37fe4620771ae70738a211.tar.gz
PeerTube-80a6c9e76fda57f01e37fe4620771ae70738a211.tar.zst
PeerTube-80a6c9e76fda57f01e37fe4620771ae70738a211.zip
Server: pod removing refractoring
Diffstat (limited to 'server/models/request.js')
-rw-r--r--server/models/request.js49
1 files changed, 3 insertions, 46 deletions
diff --git a/server/models/request.js b/server/models/request.js
index 1a99dd2ea..f11c20b52 100644
--- a/server/models/request.js
+++ b/server/models/request.js
@@ -2,7 +2,6 @@
2 2
3const each = require('async/each') 3const each = require('async/each')
4const eachLimit = require('async/eachLimit') 4const eachLimit = require('async/eachLimit')
5const map = require('lodash/map')
6const mongoose = require('mongoose') 5const mongoose = require('mongoose')
7const waterfall = require('async/waterfall') 6const waterfall = require('async/waterfall')
8 7
@@ -11,7 +10,6 @@ const logger = require('../helpers/logger')
11const requests = require('../helpers/requests') 10const requests = require('../helpers/requests')
12 11
13const Pod = mongoose.model('Pod') 12const Pod = mongoose.model('Pod')
14const Video = mongoose.model('Video')
15 13
16let timer = null 14let timer = null
17let lastRequestTimestamp = 0 15let lastRequestTimestamp = 0
@@ -218,54 +216,13 @@ function removeBadPods () {
218 }) 216 })
219 }, 217 },
220 218
221 function listVideosOfTheseBadPods (pods, callback) { 219 function removeTheseBadPods (pods, callback) {
222 if (pods.length === 0) return callback(null) 220 if (pods.length === 0) return callback(null, 0)
223
224 const urls = map(pods, 'url')
225
226 Video.listByUrls(urls, function (err, videosList) {
227 if (err) {
228 logger.error('Cannot list videos urls.', { error: err, urls: urls })
229 return callback(null, pods, [])
230 }
231
232 return callback(null, pods, videosList)
233 })
234 },
235
236 function removeVideosOfTheseBadPods (pods, videosList, callback) {
237 // We don't have to remove pods, skip
238 if (typeof pods === 'function') {
239 callback = pods
240 return callback(null)
241 }
242
243 each(videosList, function (video, callbackEach) {
244 video.remove(callbackEach)
245 }, function (err) {
246 if (err) {
247 // Don't stop the process
248 logger.error('Error while removing videos of bad pods.', { error: err })
249 return
250 }
251
252 return callback(null, pods)
253 })
254 },
255
256 function removeBadPodsFromDB (pods, callback) {
257 // We don't have to remove pods, skip
258 if (typeof pods === 'function') {
259 callback = pods
260 return callback(null)
261 }
262 221
263 each(pods, function (pod, callbackEach) { 222 each(pods, function (pod, callbackEach) {
264 pod.remove(callbackEach) 223 pod.remove(callbackEach)
265 }, function (err) { 224 }, function (err) {
266 if (err) return callback(err) 225 return callback(err, pods.length)
267
268 return callback(null, pods.length)
269 }) 226 })
270 } 227 }
271 ], function (err, numberOfPodsRemoved) { 228 ], function (err, numberOfPodsRemoved) {