aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/poolRequests.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-01-23 18:31:58 +0100
committerChocobozzz <florian.bigard@gmail.com>2016-01-23 18:31:58 +0100
commit45239549bf2659998dcf9196d86974b0b625912e (patch)
tree823d324db097400a7b5ae59a03deff54c5fd86ef /src/poolRequests.js
parent2cc8ebf134b66047cd639ee7324e1ecfd5c5fd18 (diff)
downloadPeerTube-45239549bf2659998dcf9196d86974b0b625912e.tar.gz
PeerTube-45239549bf2659998dcf9196d86974b0b625912e.tar.zst
PeerTube-45239549bf2659998dcf9196d86974b0b625912e.zip
Finalise the join in a network and add the ability to quit it
Diffstat (limited to 'src/poolRequests.js')
-rw-r--r--src/poolRequests.js32
1 files changed, 27 insertions, 5 deletions
diff --git a/src/poolRequests.js b/src/poolRequests.js
index edb12b1e8..7f422f372 100644
--- a/src/poolRequests.js
+++ b/src/poolRequests.js
@@ -6,9 +6,11 @@
6 var constants = require('./constants') 6 var constants = require('./constants')
7 var logger = require('./logger') 7 var logger = require('./logger')
8 var database = require('./database') 8 var database = require('./database')
9 var pluck = require('lodash-node/compat/collection/pluck')
9 var PoolRequestsDB = database.PoolRequestsDB 10 var PoolRequestsDB = database.PoolRequestsDB
10 var PodsDB = database.PodsDB 11 var PodsDB = database.PodsDB
11 var utils = require('./utils') 12 var utils = require('./utils')
13 var VideosDB = database.VideosDB
12 14
13 var poolRequests = {} 15 var poolRequests = {}
14 16
@@ -90,11 +92,26 @@
90 } 92 }
91 93
92 function removeBadPods () { 94 function removeBadPods () {
93 PodsDB.remove({ score: 0 }, function (err, result) { 95 PodsDB.find({ score: 0 }, { _id: 1, url: 1 }, function (err, pods) {
94 if (err) throw err 96 if (err) throw err
95 97
96 var number_removed = result.result.n 98 if (pods.length === 0) return
97 if (number_removed !== 0) logger.info('Removed %d pod.', number_removed) 99
100 var urls = pluck(pods, 'url')
101 var ids = pluck(pods, '_id')
102
103 VideosDB.remove({ podUrl: { $in: urls } }, function (err, r) {
104 if (err) logger.error('Cannot remove videos from a pod that we removing.', { error: err })
105 var videos_removed = r.result.n
106 logger.info('Removed %d videos.', videos_removed)
107
108 PodsDB.remove({ _id: { $in: ids } }, function (err, r) {
109 if (err) logger.error('Cannot remove bad pods.', { error: err })
110
111 var pods_removed = r.result.n
112 logger.info('Removed %d pods.', pods_removed)
113 })
114 })
98 }) 115 })
99 } 116 }
100 117
@@ -126,9 +143,9 @@
126 utils.makeMultipleRetryRequest(params, pods, callbackEachPodFinished, callbackAllPodsFinished) 143 utils.makeMultipleRetryRequest(params, pods, callbackEachPodFinished, callbackAllPodsFinished)
127 144
128 function callbackEachPodFinished (err, response, body, url, pod, callback_each_pod_finished) { 145 function callbackEachPodFinished (err, response, body, url, pod, callback_each_pod_finished) {
129 if (err || response.statusCode !== 200) { 146 if (err || (response.statusCode !== 200 && response.statusCode !== 204)) {
130 bad_pods.push(pod._id) 147 bad_pods.push(pod._id)
131 logger.error('Error sending secure request to %s pod.', url, { error: err }) 148 logger.error('Error sending secure request to %s pod.', url, { error: err || new Error('Status code not 20x') })
132 } else { 149 } else {
133 good_pods.push(pod._id) 150 good_pods.push(pod._id)
134 } 151 }
@@ -180,5 +197,10 @@
180 clearInterval(timer) 197 clearInterval(timer)
181 } 198 }
182 199
200 poolRequests.forceSend = function () {
201 logger.info('Force pool requests sending.')
202 makePoolRequests()
203 }
204
183 module.exports = poolRequests 205 module.exports = poolRequests
184})() 206})()