X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;ds=sidebyside;f=src%2FpoolRequests.js;h=edb12b1e82e2be76e354e2a16965d9be3a572f71;hb=656ea8f70e848b03c0b668584dd533d72b376498;hp=190fb36592db06abe8649ca42e0782955fc84bfd;hpb=1d7974c758d363a0037c2a7ed05a0848d3c027a4;p=github%2FChocobozzz%2FPeerTube.git diff --git a/src/poolRequests.js b/src/poolRequests.js index 190fb3659..edb12b1e8 100644 --- a/src/poolRequests.js +++ b/src/poolRequests.js @@ -3,6 +3,7 @@ var async = require('async') + var constants = require('./constants') var logger = require('./logger') var database = require('./database') var PoolRequestsDB = database.PoolRequestsDB @@ -11,15 +12,6 @@ var poolRequests = {} - // ----------- Constants ----------- - - // Time to wait between requests to the friends - var INTERVAL = utils.isTestInstance() ? 10000 : 60000 - var PODS_SCORE = { - MALUS: -10, - BONUS: 10 - } - // ----------- Private ----------- var timer = null @@ -90,8 +82,8 @@ function updatePodsScore (good_pods, bad_pods) { logger.info('Updating %d good pods and %d bad pods scores.', good_pods.length, bad_pods.length) - PodsDB.update({ _id: { $in: good_pods } }, { $inc: { score: PODS_SCORE.BONUS } }, { multi: true }).exec() - PodsDB.update({ _id: { $in: bad_pods } }, { $inc: { score: PODS_SCORE.MALUS } }, { multi: true }, function (err) { + PodsDB.update({ _id: { $in: good_pods } }, { $inc: { score: constants.PODS_SCORE.BONUS } }, { multi: true }).exec() + PodsDB.update({ _id: { $in: bad_pods } }, { $inc: { score: constants.PODS_SCORE.MALUS } }, { multi: true }, function (err) { if (err) throw err removeBadPods() }) @@ -121,9 +113,9 @@ } if (type === 'add') { - params.path = '/api/' + global.API_VERSION + '/remotevideos/add' + params.path = '/api/' + constants.API_VERSION + '/remotevideos/add' } else if (type === 'remove') { - params.path = '/api/' + global.API_VERSION + '/remotevideos/remove' + params.path = '/api/' + constants.API_VERSION + '/remotevideos/remove' } else { throw new Error('Unkown pool request type.') } @@ -156,7 +148,7 @@ // ----------- Public ----------- poolRequests.activate = function () { logger.info('Pool requests activated.') - timer = setInterval(makePoolRequests, INTERVAL) + timer = setInterval(makePoolRequests, constants.INTERVAL) } poolRequests.addToPoolRequests = function (id, type, request) {