aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/poolRequests.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2015-12-14 21:09:25 +0100
committerChocobozzz <florian.bigard@gmail.com>2015-12-14 22:13:03 +0100
commit656ea8f70e848b03c0b668584dd533d72b376498 (patch)
treefa49512e3a3702a80d027838e5ab7486baca185a /src/poolRequests.js
parent1d7974c758d363a0037c2a7ed05a0848d3c027a4 (diff)
downloadPeerTube-656ea8f70e848b03c0b668584dd533d72b376498.tar.gz
PeerTube-656ea8f70e848b03c0b668584dd533d72b376498.tar.zst
PeerTube-656ea8f70e848b03c0b668584dd533d72b376498.zip
Create a constants module to easily modify some constants in a test
instance for example.
Diffstat (limited to 'src/poolRequests.js')
-rw-r--r--src/poolRequests.js20
1 files changed, 6 insertions, 14 deletions
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 @@
3 3
4 var async = require('async') 4 var async = require('async')
5 5
6 var constants = require('./constants')
6 var logger = require('./logger') 7 var logger = require('./logger')
7 var database = require('./database') 8 var database = require('./database')
8 var PoolRequestsDB = database.PoolRequestsDB 9 var PoolRequestsDB = database.PoolRequestsDB
@@ -11,15 +12,6 @@
11 12
12 var poolRequests = {} 13 var poolRequests = {}
13 14
14 // ----------- Constants -----------
15
16 // Time to wait between requests to the friends
17 var INTERVAL = utils.isTestInstance() ? 10000 : 60000
18 var PODS_SCORE = {
19 MALUS: -10,
20 BONUS: 10
21 }
22
23 // ----------- Private ----------- 15 // ----------- Private -----------
24 var timer = null 16 var timer = null
25 17
@@ -90,8 +82,8 @@
90 function updatePodsScore (good_pods, bad_pods) { 82 function updatePodsScore (good_pods, bad_pods) {
91 logger.info('Updating %d good pods and %d bad pods scores.', good_pods.length, bad_pods.length) 83 logger.info('Updating %d good pods and %d bad pods scores.', good_pods.length, bad_pods.length)
92 84
93 PodsDB.update({ _id: { $in: good_pods } }, { $inc: { score: PODS_SCORE.BONUS } }, { multi: true }).exec() 85 PodsDB.update({ _id: { $in: good_pods } }, { $inc: { score: constants.PODS_SCORE.BONUS } }, { multi: true }).exec()
94 PodsDB.update({ _id: { $in: bad_pods } }, { $inc: { score: PODS_SCORE.MALUS } }, { multi: true }, function (err) { 86 PodsDB.update({ _id: { $in: bad_pods } }, { $inc: { score: constants.PODS_SCORE.MALUS } }, { multi: true }, function (err) {
95 if (err) throw err 87 if (err) throw err
96 removeBadPods() 88 removeBadPods()
97 }) 89 })
@@ -121,9 +113,9 @@
121 } 113 }
122 114
123 if (type === 'add') { 115 if (type === 'add') {
124 params.path = '/api/' + global.API_VERSION + '/remotevideos/add' 116 params.path = '/api/' + constants.API_VERSION + '/remotevideos/add'
125 } else if (type === 'remove') { 117 } else if (type === 'remove') {
126 params.path = '/api/' + global.API_VERSION + '/remotevideos/remove' 118 params.path = '/api/' + constants.API_VERSION + '/remotevideos/remove'
127 } else { 119 } else {
128 throw new Error('Unkown pool request type.') 120 throw new Error('Unkown pool request type.')
129 } 121 }
@@ -156,7 +148,7 @@
156 // ----------- Public ----------- 148 // ----------- Public -----------
157 poolRequests.activate = function () { 149 poolRequests.activate = function () {
158 logger.info('Pool requests activated.') 150 logger.info('Pool requests activated.')
159 timer = setInterval(makePoolRequests, INTERVAL) 151 timer = setInterval(makePoolRequests, constants.INTERVAL)
160 } 152 }
161 153
162 poolRequests.addToPoolRequests = function (id, type, request) { 154 poolRequests.addToPoolRequests = function (id, type, request) {