aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/requestsScheduler.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-05-11 21:19:34 +0200
committerChocobozzz <florian.bigard@gmail.com>2016-05-13 14:23:11 +0200
commitbc503c2a62dcf9aed6b8d90b68f0f27a7755ac01 (patch)
treea1fe1ad88afd29ee4d7cb05c480649d5a9c6f9a0 /server/lib/requestsScheduler.js
parent881a5e68b64e4acd43408852bbdc914643d8fac6 (diff)
downloadPeerTube-bc503c2a62dcf9aed6b8d90b68f0f27a7755ac01.tar.gz
PeerTube-bc503c2a62dcf9aed6b8d90b68f0f27a7755ac01.tar.zst
PeerTube-bc503c2a62dcf9aed6b8d90b68f0f27a7755ac01.zip
Update to standard 7. Goodbye snake_case, I used to love you
Diffstat (limited to 'server/lib/requestsScheduler.js')
-rw-r--r--server/lib/requestsScheduler.js66
1 files changed, 33 insertions, 33 deletions
diff --git a/server/lib/requestsScheduler.js b/server/lib/requestsScheduler.js
index 4953f6a91..f10de6276 100644
--- a/server/lib/requestsScheduler.js
+++ b/server/lib/requestsScheduler.js
@@ -72,7 +72,7 @@ module.exports = requestsScheduler
72 72
73// --------------------------------------------------------------------------- 73// ---------------------------------------------------------------------------
74 74
75function makeRequest (type, requests_to_make, callback) { 75function makeRequest (type, requestsToMake, callback) {
76 if (!callback) callback = function () {} 76 if (!callback) callback = function () {}
77 77
78 Pods.list(function (err, pods) { 78 Pods.list(function (err, pods) {
@@ -83,7 +83,7 @@ function makeRequest (type, requests_to_make, callback) {
83 sign: true, 83 sign: true,
84 method: 'POST', 84 method: 'POST',
85 path: null, 85 path: null,
86 data: requests_to_make 86 data: requestsToMake
87 } 87 }
88 88
89 if (type === 'add') { 89 if (type === 'add') {
@@ -94,26 +94,26 @@ function makeRequest (type, requests_to_make, callback) {
94 return callback(new Error('Unkown pool request type.')) 94 return callback(new Error('Unkown pool request type.'))
95 } 95 }
96 96
97 const bad_pods = [] 97 const badPods = []
98 const good_pods = [] 98 const goodPods = []
99 99
100 requests.makeMultipleRetryRequest(params, pods, callbackEachPodFinished, callbackAllPodsFinished) 100 requests.makeMultipleRetryRequest(params, pods, callbackEachPodFinished, callbackAllPodsFinished)
101 101
102 function callbackEachPodFinished (err, response, body, url, pod, callback_each_pod_finished) { 102 function callbackEachPodFinished (err, response, body, url, pod, callbackEachPodFinished) {
103 if (err || (response.statusCode !== 200 && response.statusCode !== 201 && response.statusCode !== 204)) { 103 if (err || (response.statusCode !== 200 && response.statusCode !== 201 && response.statusCode !== 204)) {
104 bad_pods.push(pod._id) 104 badPods.push(pod._id)
105 logger.error('Error sending secure request to %s pod.', url, { error: err || new Error('Status code not 20x') }) 105 logger.error('Error sending secure request to %s pod.', url, { error: err || new Error('Status code not 20x') })
106 } else { 106 } else {
107 good_pods.push(pod._id) 107 goodPods.push(pod._id)
108 } 108 }
109 109
110 return callback_each_pod_finished() 110 return callbackEachPodFinished()
111 } 111 }
112 112
113 function callbackAllPodsFinished (err) { 113 function callbackAllPodsFinished (err) {
114 if (err) return callback(err) 114 if (err) return callback(err)
115 115
116 updatePodsScore(good_pods, bad_pods) 116 updatePodsScore(goodPods, badPods)
117 callback(null) 117 callback(null)
118 } 118 }
119 }) 119 })
@@ -130,7 +130,7 @@ function makeRequests () {
130 130
131 if (requests.length === 0) return 131 if (requests.length === 0) return
132 132
133 const requests_to_make = { 133 const requestsToMake = {
134 add: { 134 add: {
135 ids: [], 135 ids: [],
136 requests: [] 136 requests: []
@@ -141,35 +141,35 @@ function makeRequests () {
141 } 141 }
142 } 142 }
143 143
144 async.each(requests, function (pool_request, callback_each) { 144 async.each(requests, function (poolRequest, callbackEach) {
145 if (pool_request.type === 'add') { 145 if (poolRequest.type === 'add') {
146 requests_to_make.add.requests.push(pool_request.request) 146 requestsToMake.add.requests.push(poolRequest.request)
147 requests_to_make.add.ids.push(pool_request._id) 147 requestsToMake.add.ids.push(poolRequest._id)
148 } else if (pool_request.type === 'remove') { 148 } else if (poolRequest.type === 'remove') {
149 requests_to_make.remove.requests.push(pool_request.request) 149 requestsToMake.remove.requests.push(poolRequest.request)
150 requests_to_make.remove.ids.push(pool_request._id) 150 requestsToMake.remove.ids.push(poolRequest._id)
151 } else { 151 } else {
152 logger.error('Unkown request type.', { request_type: pool_request.type }) 152 logger.error('Unkown request type.', { request_type: poolRequest.type })
153 return // abort 153 return // abort
154 } 154 }
155 155
156 callback_each() 156 callbackEach()
157 }, function () { 157 }, function () {
158 // Send the add requests 158 // Send the add requests
159 if (requests_to_make.add.requests.length !== 0) { 159 if (requestsToMake.add.requests.length !== 0) {
160 makeRequest('add', requests_to_make.add.requests, function (err) { 160 makeRequest('add', requestsToMake.add.requests, function (err) {
161 if (err) logger.error('Errors when sent add requests.', { error: err }) 161 if (err) logger.error('Errors when sent add requests.', { error: err })
162 162
163 Requests.removeRequests(requests_to_make.add.ids) 163 Requests.removeRequests(requestsToMake.add.ids)
164 }) 164 })
165 } 165 }
166 166
167 // Send the remove requests 167 // Send the remove requests
168 if (requests_to_make.remove.requests.length !== 0) { 168 if (requestsToMake.remove.requests.length !== 0) {
169 makeRequest('remove', requests_to_make.remove.requests, function (err) { 169 makeRequest('remove', requestsToMake.remove.requests, function (err) {
170 if (err) logger.error('Errors when sent remove pool requests.', { error: err }) 170 if (err) logger.error('Errors when sent remove pool requests.', { error: err })
171 171
172 Requests.removeRequests(requests_to_make.remove.ids) 172 Requests.removeRequests(requestsToMake.remove.ids)
173 }) 173 })
174 } 174 }
175 }) 175 })
@@ -188,11 +188,11 @@ function removeBadPods () {
188 const urls = map(pods, 'url') 188 const urls = map(pods, 'url')
189 const ids = map(pods, '_id') 189 const ids = map(pods, '_id')
190 190
191 Videos.listFromUrls(urls, function (err, videos_list) { 191 Videos.listFromUrls(urls, function (err, videosList) {
192 if (err) { 192 if (err) {
193 logger.error('Cannot list videos urls.', { error: err, urls: urls }) 193 logger.error('Cannot list videos urls.', { error: err, urls: urls })
194 } else { 194 } else {
195 videos.removeRemoteVideos(videos_list, function (err) { 195 videos.removeRemoteVideos(videosList, function (err) {
196 if (err) logger.error('Cannot remove remote videos.', { error: err }) 196 if (err) logger.error('Cannot remove remote videos.', { error: err })
197 }) 197 })
198 } 198 }
@@ -201,22 +201,22 @@ function removeBadPods () {
201 if (err) { 201 if (err) {
202 logger.error('Cannot remove bad pods.', { error: err }) 202 logger.error('Cannot remove bad pods.', { error: err })
203 } else { 203 } else {
204 const pods_removed = r.result.n 204 const podsRemoved = r.result.n
205 logger.info('Removed %d pods.', pods_removed) 205 logger.info('Removed %d pods.', podsRemoved)
206 } 206 }
207 }) 207 })
208 }) 208 })
209 }) 209 })
210} 210}
211 211
212function updatePodsScore (good_pods, bad_pods) { 212function updatePodsScore (goodPods, badPods) {
213 logger.info('Updating %d good pods and %d bad pods scores.', good_pods.length, bad_pods.length) 213 logger.info('Updating %d good pods and %d bad pods scores.', goodPods.length, badPods.length)
214 214
215 Pods.incrementScores(good_pods, constants.PODS_SCORE.BONUS, function (err) { 215 Pods.incrementScores(goodPods, constants.PODS_SCORE.BONUS, function (err) {
216 if (err) logger.error('Cannot increment scores of good pods.') 216 if (err) logger.error('Cannot increment scores of good pods.')
217 }) 217 })
218 218
219 Pods.incrementScores(bad_pods, constants.PODS_SCORE.MALUS, function (err) { 219 Pods.incrementScores(badPods, constants.PODS_SCORE.MALUS, function (err) {
220 if (err) logger.error('Cannot increment scores of bad pods.') 220 if (err) logger.error('Cannot increment scores of bad pods.')
221 removeBadPods() 221 removeBadPods()
222 }) 222 })