aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/request/abstract-request-scheduler.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-07-10 19:43:21 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-07-10 19:43:21 +0200
commit4771e0008dd26eadbb7eaff64255a6ec914fdadb (patch)
tree4fd58f8a3f3c2d674b936c99817b4f5fb958c5d8 /server/lib/request/abstract-request-scheduler.ts
parent7a214f746bf420defbf17fa218d90d6233551bf8 (diff)
downloadPeerTube-4771e0008dd26eadbb7eaff64255a6ec914fdadb.tar.gz
PeerTube-4771e0008dd26eadbb7eaff64255a6ec914fdadb.tar.zst
PeerTube-4771e0008dd26eadbb7eaff64255a6ec914fdadb.zip
Better typescript typing for a better world
Diffstat (limited to 'server/lib/request/abstract-request-scheduler.ts')
-rw-r--r--server/lib/request/abstract-request-scheduler.ts22
1 files changed, 16 insertions, 6 deletions
diff --git a/server/lib/request/abstract-request-scheduler.ts b/server/lib/request/abstract-request-scheduler.ts
index 0a9ff65d5..ce4e2ffd2 100644
--- a/server/lib/request/abstract-request-scheduler.ts
+++ b/server/lib/request/abstract-request-scheduler.ts
@@ -10,6 +10,15 @@ import {
10 REQUESTS_INTERVAL 10 REQUESTS_INTERVAL
11} from '../../initializers' 11} from '../../initializers'
12 12
13interface RequestsObjects<U> {
14 [ id: string ]: {
15 toPod: PodInstance
16 endpoint: string
17 ids: number[] // ids
18 datas: U[]
19 }
20}
21
13abstract class AbstractRequestScheduler <T> { 22abstract class AbstractRequestScheduler <T> {
14 requestInterval: number 23 requestInterval: number
15 limitPods: number 24 limitPods: number
@@ -27,7 +36,7 @@ abstract class AbstractRequestScheduler <T> {
27 36
28 abstract getRequestModel (): AbstractRequestClass<T> 37 abstract getRequestModel (): AbstractRequestClass<T>
29 abstract getRequestToPodModel (): AbstractRequestToPodClass 38 abstract getRequestToPodModel (): AbstractRequestToPodClass
30 abstract buildRequestObjects (requestsGrouped: T): {} 39 abstract buildRequestsObjects (requestsGrouped: T): RequestsObjects<any>
31 40
32 activate () { 41 activate () {
33 logger.info('Requests scheduler activated.') 42 logger.info('Requests scheduler activated.')
@@ -67,7 +76,7 @@ abstract class AbstractRequestScheduler <T> {
67 // --------------------------------------------------------------------------- 76 // ---------------------------------------------------------------------------
68 77
69 // Make a requests to friends of a certain type 78 // Make a requests to friends of a certain type
70 protected makeRequest (toPod: PodInstance, requestEndpoint: string, requestsToMake: Object) { 79 protected makeRequest (toPod: PodInstance, requestEndpoint: string, requestsToMake: any) {
71 const params = { 80 const params = {
72 toPod: toPod, 81 toPod: toPod,
73 method: 'POST' as 'POST', 82 method: 'POST' as 'POST',
@@ -95,7 +104,7 @@ abstract class AbstractRequestScheduler <T> {
95 return this.getRequestModel().listWithLimitAndRandom(this.limitPods, this.limitPerPod) 104 return this.getRequestModel().listWithLimitAndRandom(this.limitPods, this.limitPerPod)
96 .then((requestsGrouped: T) => { 105 .then((requestsGrouped: T) => {
97 // We want to group requests by destinations pod and endpoint 106 // We want to group requests by destinations pod and endpoint
98 const requestsToMake = this.buildRequestObjects(requestsGrouped) 107 const requestsToMake = this.buildRequestsObjects(requestsGrouped)
99 108
100 // If there are no requests, abort 109 // If there are no requests, abort
101 if (isEmpty(requestsToMake) === true) { 110 if (isEmpty(requestsToMake) === true) {
@@ -105,8 +114,8 @@ abstract class AbstractRequestScheduler <T> {
105 114
106 logger.info('Making "%s" to friends.', this.description) 115 logger.info('Making "%s" to friends.', this.description)
107 116
108 const goodPods = [] 117 const goodPods: number[] = []
109 const badPods = [] 118 const badPods: number[] = []
110 119
111 return Promise.map(Object.keys(requestsToMake), hashKey => { 120 return Promise.map(Object.keys(requestsToMake), hashKey => {
112 const requestToMake = requestsToMake[hashKey] 121 const requestToMake = requestsToMake[hashKey]
@@ -149,5 +158,6 @@ abstract class AbstractRequestScheduler <T> {
149// --------------------------------------------------------------------------- 158// ---------------------------------------------------------------------------
150 159
151export { 160export {
152 AbstractRequestScheduler 161 AbstractRequestScheduler,
162 RequestsObjects
153} 163}