aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/request.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-10-01 15:33:27 +0200
committerChocobozzz <florian.bigard@gmail.com>2016-10-01 15:33:27 +0200
commit5abeec313f897bbb1f1f39c3849675ec9a77d506 (patch)
tree6ded96dd660e5427d28d05a6ed191687b0f79010 /server/models/request.js
parent1ab844d8593fa84dfe65cad6b5bbf0e45efd7886 (diff)
downloadPeerTube-5abeec313f897bbb1f1f39c3849675ec9a77d506.tar.gz
PeerTube-5abeec313f897bbb1f1f39c3849675ec9a77d506.tar.zst
PeerTube-5abeec313f897bbb1f1f39c3849675ec9a77d506.zip
Server: fix remaining milli seconds before the next requests feature
Diffstat (limited to 'server/models/request.js')
-rw-r--r--server/models/request.js21
1 files changed, 18 insertions, 3 deletions
diff --git a/server/models/request.js b/server/models/request.js
index 73b17dc8c..2d50d94e0 100644
--- a/server/models/request.js
+++ b/server/models/request.js
@@ -14,6 +14,7 @@ const Pod = mongoose.model('Pod')
14const Video = mongoose.model('Video') 14const Video = mongoose.model('Video')
15 15
16let timer = null 16let timer = null
17let lastRequestTimestamp = 0
17 18
18// --------------------------------------------------------------------------- 19// ---------------------------------------------------------------------------
19 20
@@ -27,7 +28,8 @@ RequestSchema.statics = {
27 deactivate, 28 deactivate,
28 flush, 29 flush,
29 forceSend, 30 forceSend,
30 list 31 list,
32 remainingMilliSeconds
31} 33}
32 34
33RequestSchema.pre('save', function (next) { 35RequestSchema.pre('save', function (next) {
@@ -54,12 +56,19 @@ mongoose.model('Request', RequestSchema)
54 56
55function activate () { 57function activate () {
56 logger.info('Requests scheduler activated.') 58 logger.info('Requests scheduler activated.')
57 timer = setInterval(makeRequests.bind(this), constants.REQUESTS_INTERVAL) 59 lastRequestTimestamp = Date.now()
60
61 const self = this
62 timer = setInterval(function () {
63 lastRequestTimestamp = Date.now()
64 makeRequests.call(self)
65 }, constants.REQUESTS_INTERVAL)
58} 66}
59 67
60function deactivate () { 68function deactivate () {
61 logger.info('Requests scheduler deactivated.') 69 logger.info('Requests scheduler deactivated.')
62 clearInterval(timer) 70 clearInterval(timer)
71 timer = null
63} 72}
64 73
65function flush () { 74function flush () {
@@ -77,6 +86,12 @@ function list (callback) {
77 this.find({ }, callback) 86 this.find({ }, callback)
78} 87}
79 88
89function remainingMilliSeconds () {
90 if (timer === null) return -1
91
92 return constants.REQUESTS_INTERVAL - (Date.now() - lastRequestTimestamp)
93}
94
80// --------------------------------------------------------------------------- 95// ---------------------------------------------------------------------------
81 96
82// Make a requests to friends of a certain type 97// Make a requests to friends of a certain type
@@ -159,7 +174,7 @@ function makeRequests () {
159 return callbackEach() 174 return callbackEach()
160 } 175 }
161 176
162 // Maybe the pod is not our friend anymore so simply remove them 177 // Maybe the pod is not our friend anymore so simply remove it
163 if (!toPod) { 178 if (!toPod) {
164 removePodOf.call(self, requestToMake.ids, toPodId) 179 removePodOf.call(self, requestToMake.ids, toPodId)
165 return callbackEach() 180 return callbackEach()