aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
Diffstat (limited to 'server/models')
-rw-r--r--server/models/request.js17
1 files changed, 14 insertions, 3 deletions
diff --git a/server/models/request.js b/server/models/request.js
index f11c20b52..34a4287ea 100644
--- a/server/models/request.js
+++ b/server/models/request.js
@@ -128,7 +128,9 @@ function makeRequest (toPod, requestsToMake, callback) {
128function makeRequests () { 128function makeRequests () {
129 const self = this 129 const self = this
130 130
131 listWithLimit.call(self, constants.REQUESTS_LIMIT, function (err, requests) { 131 // We limit the size of the requests (REQUESTS_LIMIT)
132 // We don't want to stuck with the same failing requests so we get a random list
133 listWithLimitAndRandom.call(self, constants.REQUESTS_LIMIT, function (err, requests) {
132 if (err) { 134 if (err) {
133 logger.error('Cannot get the list of requests.', { err: err }) 135 logger.error('Cannot get the list of requests.', { err: err })
134 return // Abort 136 return // Abort
@@ -249,8 +251,17 @@ function updatePodsScore (goodPods, badPods) {
249 }) 251 })
250} 252}
251 253
252function listWithLimit (limit, callback) { 254function listWithLimitAndRandom (limit, callback) {
253 this.find({ }, { _id: 1, request: 1, to: 1 }).sort({ _id: 1 }).limit(limit).exec(callback) 255 const self = this
256
257 self.count(function (err, count) {
258 if (err) return callback(err)
259
260 let start = Math.floor(Math.random() * count) - limit
261 if (start < 0) start = 0
262
263 self.find({ }, { _id: 1, request: 1, to: 1 }).sort({ _id: 1 }).skip(start).limit(limit).exec(callback)
264 })
254} 265}
255 266
256function removeAll (callback) { 267function removeAll (callback) {