]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/request/abstract-request-scheduler.ts
Remove any typing from server
[github/Chocobozzz/PeerTube.git] / server / lib / request / abstract-request-scheduler.ts
index dd77fddb71fc2b4b94cccc13e9823b40ff280c32..ce4e2ffd2bc0d90e49c374a6162135c9faf5c094 100644 (file)
@@ -10,6 +10,15 @@ import {
   REQUESTS_INTERVAL
 } from '../../initializers'
 
+interface RequestsObjects<U> {
+  [ id: string ]: {
+    toPod: PodInstance
+    endpoint: string
+    ids: number[] // ids
+    datas: U[]
+  }
+}
+
 abstract class AbstractRequestScheduler <T> {
   requestInterval: number
   limitPods: number
@@ -27,7 +36,7 @@ abstract class AbstractRequestScheduler <T> {
 
   abstract getRequestModel (): AbstractRequestClass<T>
   abstract getRequestToPodModel (): AbstractRequestToPodClass
-  abstract buildRequestObjects (requestsGrouped: T): {}
+  abstract buildRequestsObjects (requestsGrouped: T): RequestsObjects<any>
 
   activate () {
     logger.info('Requests scheduler activated.')
@@ -67,10 +76,9 @@ abstract class AbstractRequestScheduler <T> {
   // ---------------------------------------------------------------------------
 
   // Make a requests to friends of a certain type
-  protected makeRequest (toPod: PodInstance, requestEndpoint: string, requestsToMake: Object) {
+  protected makeRequest (toPod: PodInstance, requestEndpoint: string, requestsToMake: any) {
     const params = {
       toPod: toPod,
-      sign: true, // Prove our identity
       method: 'POST' as 'POST',
       path: '/api/' + API_VERSION + '/remote/' + requestEndpoint,
       data: requestsToMake // Requests we need to make
@@ -85,7 +93,7 @@ abstract class AbstractRequestScheduler <T> {
         }
       })
       .catch(err => {
-        logger.error('Error sending secure request to %s pod.', toPod.host, { error: err })
+        logger.error('Error sending secure request to %s pod.', toPod.host, err)
 
         throw err
       })
@@ -96,7 +104,7 @@ abstract class AbstractRequestScheduler <T> {
     return this.getRequestModel().listWithLimitAndRandom(this.limitPods, this.limitPerPod)
       .then((requestsGrouped: T) => {
         // We want to group requests by destinations pod and endpoint
-        const requestsToMake = this.buildRequestObjects(requestsGrouped)
+        const requestsToMake = this.buildRequestsObjects(requestsGrouped)
 
         // If there are no requests, abort
         if (isEmpty(requestsToMake) === true) {
@@ -106,8 +114,8 @@ abstract class AbstractRequestScheduler <T> {
 
         logger.info('Making "%s" to friends.', this.description)
 
-        const goodPods = []
-        const badPods = []
+        const goodPods: number[] = []
+        const badPods: number[] = []
 
         return Promise.map(Object.keys(requestsToMake), hashKey => {
           const requestToMake = requestsToMake[hashKey]
@@ -125,7 +133,7 @@ abstract class AbstractRequestScheduler <T> {
             })
             .catch(err => {
               badPods.push(requestToMake.toPod.id)
-              logger.info('Cannot make request to %s.', toPod.host, { error: err })
+              logger.info('Cannot make request to %s.', toPod.host, err)
             })
         }, { concurrency: REQUESTS_IN_PARALLEL }).then(() => ({ goodPods, badPods }))
       })
@@ -150,5 +158,6 @@ abstract class AbstractRequestScheduler <T> {
 // ---------------------------------------------------------------------------
 
 export {
-  AbstractRequestScheduler
+  AbstractRequestScheduler,
+  RequestsObjects
 }