aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/poolRequests.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-02-05 19:02:05 +0100
committerChocobozzz <florian.bigard@gmail.com>2016-02-05 19:02:05 +0100
commit8425cb894d4867d26fd5f7fae7862b0669f3c717 (patch)
tree5e2f00a8219e198f2dd074ca13f3ae681174228f /lib/poolRequests.js
parentdac0a5319ab1c52a0958647b1593f85339b77e29 (diff)
downloadPeerTube-8425cb894d4867d26fd5f7fae7862b0669f3c717.tar.gz
PeerTube-8425cb894d4867d26fd5f7fae7862b0669f3c717.tar.zst
PeerTube-8425cb894d4867d26fd5f7fae7862b0669f3c717.zip
Error handling mini refractoring
Diffstat (limited to 'lib/poolRequests.js')
-rw-r--r--lib/poolRequests.js43
1 files changed, 29 insertions, 14 deletions
diff --git a/lib/poolRequests.js b/lib/poolRequests.js
index f4ab434ad..ccc3489ab 100644
--- a/lib/poolRequests.js
+++ b/lib/poolRequests.js
@@ -44,7 +44,7 @@
44 if (!callback) callback = function () {} 44 if (!callback) callback = function () {}
45 45
46 Pods.list(function (err, pods) { 46 Pods.list(function (err, pods) {
47 if (err) throw err 47 if (err) return callback(err)
48 48
49 var params = { 49 var params = {
50 encrypt: true, 50 encrypt: true,
@@ -59,7 +59,7 @@
59 } else if (type === 'remove') { 59 } else if (type === 'remove') {
60 params.path = '/api/' + constants.API_VERSION + '/remotevideos/remove' 60 params.path = '/api/' + constants.API_VERSION + '/remotevideos/remove'
61 } else { 61 } else {
62 throw new Error('Unkown pool request type.') 62 return callback(new Error('Unkown pool request type.'))
63 } 63 }
64 64
65 var bad_pods = [] 65 var bad_pods = []
@@ -91,7 +91,10 @@
91 logger.info('Making pool requests to friends.') 91 logger.info('Making pool requests to friends.')
92 92
93 PoolRequests.list(function (err, pool_requests) { 93 PoolRequests.list(function (err, pool_requests) {
94 if (err) throw err 94 if (err) {
95 logger.error('Cannot get the list of pool requests.', { err: err })
96 return // Abort
97 }
95 98
96 if (pool_requests.length === 0) return 99 if (pool_requests.length === 0) return
97 100
@@ -114,7 +117,8 @@
114 requests_to_make.remove.requests.push(pool_request.request) 117 requests_to_make.remove.requests.push(pool_request.request)
115 requests_to_make.remove.ids.push(pool_request._id) 118 requests_to_make.remove.ids.push(pool_request._id)
116 } else { 119 } else {
117 throw new Error('Unkown pool request type.') 120 logger.error('Unkown pool request type.', { request_type: pool_request.type })
121 return // abort
118 } 122 }
119 123
120 callback_each() 124 callback_each()
@@ -142,7 +146,10 @@
142 146
143 function removeBadPods () { 147 function removeBadPods () {
144 Pods.findBadPods(function (err, pods) { 148 Pods.findBadPods(function (err, pods) {
145 if (err) throw err 149 if (err) {
150 logger.error('Cannot find bad pods.', { error: err })
151 return // abort
152 }
146 153
147 if (pods.length === 0) return 154 if (pods.length === 0) return
148 155
@@ -150,15 +157,20 @@
150 var ids = pluck(pods, '_id') 157 var ids = pluck(pods, '_id')
151 158
152 Videos.removeAllRemotesOf(urls, function (err, r) { 159 Videos.removeAllRemotesOf(urls, function (err, r) {
153 if (err) logger.error('Cannot remove videos from a pod that we removing.', { error: err }) 160 if (err) {
154 var videos_removed = r.result.n 161 logger.error('Cannot remove videos from a pod that we removing.', { error: err })
155 logger.info('Removed %d videos.', videos_removed) 162 } else {
163 var videos_removed = r.result.n
164 logger.info('Removed %d videos.', videos_removed)
165 }
156 166
157 Pods.removeAllByIds(ids, function (err, r) { 167 Pods.removeAllByIds(ids, function (err, r) {
158 if (err) logger.error('Cannot remove bad pods.', { error: err }) 168 if (err) {
159 169 logger.error('Cannot remove bad pods.', { error: err })
160 var pods_removed = r.result.n 170 } else {
161 logger.info('Removed %d pods.', pods_removed) 171 var pods_removed = r.result.n
172 logger.info('Removed %d pods.', pods_removed)
173 }
162 }) 174 })
163 }) 175 })
164 }) 176 })
@@ -167,9 +179,12 @@
167 function updatePodsScore (good_pods, bad_pods) { 179 function updatePodsScore (good_pods, bad_pods) {
168 logger.info('Updating %d good pods and %d bad pods scores.', good_pods.length, bad_pods.length) 180 logger.info('Updating %d good pods and %d bad pods scores.', good_pods.length, bad_pods.length)
169 181
170 Pods.incrementScores(good_pods, constants.PODS_SCORE.BONUS) 182 Pods.incrementScores(good_pods, constants.PODS_SCORE.BONUS, function (err) {
183 if (err) logger.error('Cannot increment scores of good pods.')
184 })
185
171 Pods.incrementScores(bad_pods, constants.PODS_SCORE.MALUS, function (err) { 186 Pods.incrementScores(bad_pods, constants.PODS_SCORE.MALUS, function (err) {
172 if (err) throw err 187 if (err) logger.error('Cannot increment scores of bad pods.')
173 removeBadPods() 188 removeBadPods()
174 }) 189 })
175 } 190 }