diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-02-05 18:03:20 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-02-05 18:03:20 +0100 |
commit | dac0a5319ab1c52a0958647b1593f85339b77e29 (patch) | |
tree | 716bc9e7e0b9fd3a7066530e50e73991fb278d05 /lib/poolRequests.js | |
parent | a5fa04b0cce851f680a45055f57ed2c3d22f1c82 (diff) | |
download | PeerTube-dac0a5319ab1c52a0958647b1593f85339b77e29.tar.gz PeerTube-dac0a5319ab1c52a0958647b1593f85339b77e29.tar.zst PeerTube-dac0a5319ab1c52a0958647b1593f85339b77e29.zip |
Split utils file
Diffstat (limited to 'lib/poolRequests.js')
-rw-r--r-- | lib/poolRequests.js | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/lib/poolRequests.js b/lib/poolRequests.js index 796f06149..f4ab434ad 100644 --- a/lib/poolRequests.js +++ b/lib/poolRequests.js | |||
@@ -8,7 +8,7 @@ | |||
8 | var logger = require('../helpers/logger') | 8 | var logger = require('../helpers/logger') |
9 | var Pods = require('../models/pods') | 9 | var Pods = require('../models/pods') |
10 | var PoolRequests = require('../models/poolRequests') | 10 | var PoolRequests = require('../models/poolRequests') |
11 | var utils = require('../helpers/utils') | 11 | var requests = require('../helpers/requests') |
12 | var Videos = require('../models/videos') | 12 | var Videos = require('../models/videos') |
13 | 13 | ||
14 | var timer = null | 14 | var timer = null |
@@ -40,7 +40,7 @@ | |||
40 | 40 | ||
41 | // --------------------------------------------------------------------------- | 41 | // --------------------------------------------------------------------------- |
42 | 42 | ||
43 | function makePoolRequest (type, requests, callback) { | 43 | function makePoolRequest (type, requests_to_make, callback) { |
44 | if (!callback) callback = function () {} | 44 | if (!callback) callback = function () {} |
45 | 45 | ||
46 | Pods.list(function (err, pods) { | 46 | Pods.list(function (err, pods) { |
@@ -51,7 +51,7 @@ | |||
51 | sign: true, | 51 | sign: true, |
52 | method: 'POST', | 52 | method: 'POST', |
53 | path: null, | 53 | path: null, |
54 | data: requests | 54 | data: requests_to_make |
55 | } | 55 | } |
56 | 56 | ||
57 | if (type === 'add') { | 57 | if (type === 'add') { |
@@ -65,7 +65,7 @@ | |||
65 | var bad_pods = [] | 65 | var bad_pods = [] |
66 | var good_pods = [] | 66 | var good_pods = [] |
67 | 67 | ||
68 | utils.makeMultipleRetryRequest(params, pods, callbackEachPodFinished, callbackAllPodsFinished) | 68 | requests.makeMultipleRetryRequest(params, pods, callbackEachPodFinished, callbackAllPodsFinished) |
69 | 69 | ||
70 | function callbackEachPodFinished (err, response, body, url, pod, callback_each_pod_finished) { | 70 | function callbackEachPodFinished (err, response, body, url, pod, callback_each_pod_finished) { |
71 | if (err || (response.statusCode !== 200 && response.statusCode !== 204)) { | 71 | if (err || (response.statusCode !== 200 && response.statusCode !== 204)) { |
@@ -95,7 +95,7 @@ | |||
95 | 95 | ||
96 | if (pool_requests.length === 0) return | 96 | if (pool_requests.length === 0) return |
97 | 97 | ||
98 | var requests = { | 98 | var requests_to_make = { |
99 | add: { | 99 | add: { |
100 | ids: [], | 100 | ids: [], |
101 | requests: [] | 101 | requests: [] |
@@ -108,11 +108,11 @@ | |||
108 | 108 | ||
109 | async.each(pool_requests, function (pool_request, callback_each) { | 109 | async.each(pool_requests, function (pool_request, callback_each) { |
110 | if (pool_request.type === 'add') { | 110 | if (pool_request.type === 'add') { |
111 | requests.add.requests.push(pool_request.request) | 111 | requests_to_make.add.requests.push(pool_request.request) |
112 | requests.add.ids.push(pool_request._id) | 112 | requests_to_make.add.ids.push(pool_request._id) |
113 | } else if (pool_request.type === 'remove') { | 113 | } else if (pool_request.type === 'remove') { |
114 | requests.remove.requests.push(pool_request.request) | 114 | requests_to_make.remove.requests.push(pool_request.request) |
115 | requests.remove.ids.push(pool_request._id) | 115 | requests_to_make.remove.ids.push(pool_request._id) |
116 | } else { | 116 | } else { |
117 | throw new Error('Unkown pool request type.') | 117 | throw new Error('Unkown pool request type.') |
118 | } | 118 | } |
@@ -120,20 +120,20 @@ | |||
120 | callback_each() | 120 | callback_each() |
121 | }, function () { | 121 | }, function () { |
122 | // Send the add requests | 122 | // Send the add requests |
123 | if (requests.add.requests.length !== 0) { | 123 | if (requests_to_make.add.requests.length !== 0) { |
124 | makePoolRequest('add', requests.add.requests, function (err) { | 124 | makePoolRequest('add', requests_to_make.add.requests, function (err) { |
125 | if (err) logger.error('Errors when sent add pool requests.', { error: err }) | 125 | if (err) logger.error('Errors when sent add pool requests.', { error: err }) |
126 | 126 | ||
127 | PoolRequests.removeRequests(requests.add.ids) | 127 | PoolRequests.removeRequests(requests_to_make.add.ids) |
128 | }) | 128 | }) |
129 | } | 129 | } |
130 | 130 | ||
131 | // Send the remove requests | 131 | // Send the remove requests |
132 | if (requests.remove.requests.length !== 0) { | 132 | if (requests_to_make.remove.requests.length !== 0) { |
133 | makePoolRequest('remove', requests.remove.requests, function (err) { | 133 | makePoolRequest('remove', requests_to_make.remove.requests, function (err) { |
134 | if (err) logger.error('Errors when sent remove pool requests.', { error: err }) | 134 | if (err) logger.error('Errors when sent remove pool requests.', { error: err }) |
135 | 135 | ||
136 | PoolRequests.removeRequests(requests.remove.ids) | 136 | PoolRequests.removeRequests(requests_to_make.remove.ids) |
137 | }) | 137 | }) |
138 | } | 138 | } |
139 | }) | 139 | }) |