aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/request/base-request-scheduler.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-06-10 22:15:25 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-06-10 22:15:25 +0200
commit69818c9394366b954b6ba3bd697bd9d2b09f2a16 (patch)
treead199a18ec3c322460d6f9523fc383ee562554e0 /server/lib/request/base-request-scheduler.ts
parent4d4e5cd4dca78480ec7f40e747f424cd107376a4 (diff)
downloadPeerTube-69818c9394366b954b6ba3bd697bd9d2b09f2a16.tar.gz
PeerTube-69818c9394366b954b6ba3bd697bd9d2b09f2a16.tar.zst
PeerTube-69818c9394366b954b6ba3bd697bd9d2b09f2a16.zip
Type functions
Diffstat (limited to 'server/lib/request/base-request-scheduler.ts')
-rw-r--r--server/lib/request/base-request-scheduler.ts16
1 files changed, 9 insertions, 7 deletions
diff --git a/server/lib/request/base-request-scheduler.ts b/server/lib/request/base-request-scheduler.ts
index b7ef6abf9..26bdc2bff 100644
--- a/server/lib/request/base-request-scheduler.ts
+++ b/server/lib/request/base-request-scheduler.ts
@@ -2,6 +2,7 @@ import * as eachLimit from 'async/eachLimit'
2 2
3import { database as db } from '../../initializers/database' 3import { database as db } from '../../initializers/database'
4import { logger, makeSecureRequest } from '../../helpers' 4import { logger, makeSecureRequest } from '../../helpers'
5import { PodInstance } from '../../models'
5import { 6import {
6 API_VERSION, 7 API_VERSION,
7 REQUESTS_IN_PARALLEL, 8 REQUESTS_IN_PARALLEL,
@@ -9,11 +10,12 @@ import {
9} from '../../initializers' 10} from '../../initializers'
10 11
11abstract class BaseRequestScheduler { 12abstract class BaseRequestScheduler {
13 requestInterval: number
14 limitPods: number
15 limitPerPod: number
16
12 protected lastRequestTimestamp: number 17 protected lastRequestTimestamp: number
13 protected timer: NodeJS.Timer 18 protected timer: NodeJS.Timer
14 protected requestInterval: number
15 protected limitPods: number
16 protected limitPerPod: number
17 protected description: string 19 protected description: string
18 20
19 constructor () { 21 constructor () {
@@ -53,24 +55,24 @@ abstract class BaseRequestScheduler {
53 return REQUESTS_INTERVAL - (Date.now() - this.lastRequestTimestamp) 55 return REQUESTS_INTERVAL - (Date.now() - this.lastRequestTimestamp)
54 } 56 }
55 57
56 remainingRequestsCount (callback) { 58 remainingRequestsCount (callback: (err: Error, total: number) => void) {
57 return this.getRequestModel().countTotalRequests(callback) 59 return this.getRequestModel().countTotalRequests(callback)
58 } 60 }
59 61
60 flush (callback) { 62 flush (callback: (err: Error) => void) {
61 this.getRequestModel().removeAll(callback) 63 this.getRequestModel().removeAll(callback)
62 } 64 }
63 65
64 // --------------------------------------------------------------------------- 66 // ---------------------------------------------------------------------------
65 67
66 // Make a requests to friends of a certain type 68 // Make a requests to friends of a certain type
67 protected makeRequest (toPod, requestEndpoint, requestsToMake, callback) { 69 protected makeRequest (toPod: PodInstance, requestEndpoint: string, requestsToMake: Object, callback) {
68 if (!callback) callback = function () { /* empty */ } 70 if (!callback) callback = function () { /* empty */ }
69 71
70 const params = { 72 const params = {
71 toPod: toPod, 73 toPod: toPod,
72 sign: true, // Prove our identity 74 sign: true, // Prove our identity
73 method: 'POST', 75 method: 'POST' as 'POST',
74 path: '/api/' + API_VERSION + '/remote/' + requestEndpoint, 76 path: '/api/' + API_VERSION + '/remote/' + requestEndpoint,
75 data: requestsToMake // Requests we need to make 77 data: requestsToMake // Requests we need to make
76 } 78 }