aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/poolRequests.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-02-05 19:41:22 +0100
committerChocobozzz <florian.bigard@gmail.com>2016-02-05 19:41:22 +0100
commit1fe5076f63e0d3b291c4b9a2295220713f982f91 (patch)
treeed776cc0d43a4371c41f2d6c9f36a8155f68c042 /lib/poolRequests.js
parent8425cb894d4867d26fd5f7fae7862b0669f3c717 (diff)
downloadPeerTube-1fe5076f63e0d3b291c4b9a2295220713f982f91.tar.gz
PeerTube-1fe5076f63e0d3b291c4b9a2295220713f982f91.tar.zst
PeerTube-1fe5076f63e0d3b291c4b9a2295220713f982f91.zip
Move the creation of requests in lib instead of model for poolrequests
Diffstat (limited to 'lib/poolRequests.js')
-rw-r--r--lib/poolRequests.js42
1 files changed, 37 insertions, 5 deletions
diff --git a/lib/poolRequests.js b/lib/poolRequests.js
index ccc3489ab..5b7d5489d 100644
--- a/lib/poolRequests.js
+++ b/lib/poolRequests.js
@@ -15,10 +15,47 @@
15 15
16 var poolRequests = { 16 var poolRequests = {
17 activate: activate, 17 activate: activate,
18 addRequest: addRequest,
18 deactivate: deactivate, 19 deactivate: deactivate,
19 forceSend: forceSend 20 forceSend: forceSend
20 } 21 }
21 22
23 function activate () {
24 logger.info('Pool requests activated.')
25 timer = setInterval(makePoolRequests, constants.INTERVAL)
26 }
27
28 function addRequest (id, type, request) {
29 logger.debug('Add request to the pool requests.', { id: id, type: type, request: request })
30
31 PoolRequests.findById(id, function (err, entity) {
32 if (err) {
33 logger.error('Cannot find one pool request.', { error: err })
34 return // Abort
35 }
36
37 if (entity) {
38 if (entity.type === type) {
39 logger.error('Cannot insert two same requests.')
40 return // Abort
41 }
42
43 // Remove the request of the other type
44 PoolRequests.removeById(id, function (err) {
45 if (err) {
46 logger.error('Cannot remove a pool request.', { error: err })
47 return // Abort
48 }
49 })
50 } else {
51 PoolRequests.create(id, type, request, function (err) {
52 logger.error('Cannot create a pool request.', { error: err })
53 return // Abort
54 })
55 }
56 })
57 }
58
22 function deactivate () { 59 function deactivate () {
23 logger.info('Pool requests deactivated.') 60 logger.info('Pool requests deactivated.')
24 clearInterval(timer) 61 clearInterval(timer)
@@ -29,11 +66,6 @@
29 makePoolRequests() 66 makePoolRequests()
30 } 67 }
31 68
32 function activate () {
33 logger.info('Pool requests activated.')
34 timer = setInterval(makePoolRequests, constants.INTERVAL)
35 }
36
37 // --------------------------------------------------------------------------- 69 // ---------------------------------------------------------------------------
38 70
39 module.exports = poolRequests 71 module.exports = poolRequests