From 69818c9394366b954b6ba3bd697bd9d2b09f2a16 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Sat, 10 Jun 2017 22:15:25 +0200 Subject: Type functions --- server/lib/friends.ts | 94 +++++++++++++--------- server/lib/jobs/handlers/index.ts | 10 ++- server/lib/jobs/handlers/video-transcoder.ts | 7 +- server/lib/jobs/job-scheduler.ts | 24 +++--- server/lib/oauth-model.ts | 15 ++-- server/lib/request/base-request-scheduler.ts | 16 ++-- server/lib/request/index.ts | 1 + server/lib/request/request-scheduler.ts | 23 +++--- .../lib/request/request-video-event-scheduler.ts | 21 ++--- server/lib/request/request-video-qadu-scheduler.ts | 21 ++--- 10 files changed, 140 insertions(+), 92 deletions(-) (limited to 'server/lib') diff --git a/server/lib/friends.ts b/server/lib/friends.ts index 6b0fbd2bf..e097f9254 100644 --- a/server/lib/friends.ts +++ b/server/lib/friends.ts @@ -1,5 +1,6 @@ import { each, eachLimit, eachSeries, series, waterfall } from 'async' import * as request from 'request' +import * as Sequelize from 'sequelize' import { database as db } from '../initializers/database' import { @@ -19,9 +20,18 @@ import { } from '../helpers' import { RequestScheduler, + RequestSchedulerOptions, + RequestVideoQaduScheduler, - RequestVideoEventScheduler + RequestVideoQaduSchedulerOptions, + + RequestVideoEventScheduler, + RequestVideoEventSchedulerOptions } from './request' +import { PodInstance, VideoInstance } from '../models' + +type QaduParam = { videoId: string, type: string } +type EventParam = { videoId: string, type: string } const ENDPOINT_ACTIONS = REQUEST_ENDPOINT_ACTIONS[REQUEST_ENDPOINTS.VIDEOS] @@ -35,7 +45,7 @@ function activateSchedulers () { requestVideoEventScheduler.activate() } -function addVideoToFriends (videoData, transaction, callback) { +function addVideoToFriends (videoData: Object, transaction: Sequelize.Transaction, callback: (err: Error) => void) { const options = { type: ENDPOINT_ACTIONS.ADD, endpoint: REQUEST_ENDPOINTS.VIDEOS, @@ -45,7 +55,7 @@ function addVideoToFriends (videoData, transaction, callback) { createRequest(options, callback) } -function updateVideoToFriends (videoData, transaction, callback) { +function updateVideoToFriends (videoData: Object, transaction: Sequelize.Transaction, callback: (err: Error) => void) { const options = { type: ENDPOINT_ACTIONS.UPDATE, endpoint: REQUEST_ENDPOINTS.VIDEOS, @@ -55,35 +65,37 @@ function updateVideoToFriends (videoData, transaction, callback) { createRequest(options, callback) } -function removeVideoToFriends (videoParams) { +function removeVideoToFriends (videoParams: Object) { const options = { type: ENDPOINT_ACTIONS.REMOVE, endpoint: REQUEST_ENDPOINTS.VIDEOS, - data: videoParams + data: videoParams, + transaction: null } createRequest(options) } -function reportAbuseVideoToFriend (reportData, video) { +function reportAbuseVideoToFriend (reportData: Object, video: VideoInstance) { const options = { type: ENDPOINT_ACTIONS.REPORT_ABUSE, endpoint: REQUEST_ENDPOINTS.VIDEOS, data: reportData, - toIds: [ video.Author.podId ] + toIds: [ video.Author.podId ], + transaction: null } createRequest(options) } -function quickAndDirtyUpdateVideoToFriends (qaduParams, transaction?, callback?) { +function quickAndDirtyUpdateVideoToFriends (qaduParam: QaduParam, transaction?: Sequelize.Transaction, callback?: (err: Error) => void) { const options = { - videoId: qaduParams.videoId, - type: qaduParams.type, + videoId: qaduParam.videoId, + type: qaduParam.type, transaction } return createVideoQaduRequest(options, callback) } -function quickAndDirtyUpdatesVideoToFriends (qadusParams, transaction, finalCallback) { +function quickAndDirtyUpdatesVideoToFriends (qadusParams: QaduParam[], transaction: Sequelize.Transaction, finalCallback: (err: Error) => void) { const tasks = [] qadusParams.forEach(function (qaduParams) { @@ -97,16 +109,16 @@ function quickAndDirtyUpdatesVideoToFriends (qadusParams, transaction, finalCall series(tasks, finalCallback) } -function addEventToRemoteVideo (eventParams, transaction?, callback?) { +function addEventToRemoteVideo (eventParam: EventParam, transaction?: Sequelize.Transaction, callback?: (err: Error) => void) { const options = { - videoId: eventParams.videoId, - type: eventParams.type, + videoId: eventParam.videoId, + type: eventParam.type, transaction } createVideoEventRequest(options, callback) } -function addEventsToRemoteVideo (eventsParams, transaction, finalCallback) { +function addEventsToRemoteVideo (eventsParams: EventParam[], transaction: Sequelize.Transaction, finalCallback: (err: Error) => void) { const tasks = [] eventsParams.forEach(function (eventParams) { @@ -120,7 +132,7 @@ function addEventsToRemoteVideo (eventsParams, transaction, finalCallback) { series(tasks, finalCallback) } -function hasFriends (callback) { +function hasFriends (callback: (err: Error, hasFriends?: boolean) => void) { db.Pod.countAll(function (err, count) { if (err) return callback(err) @@ -129,7 +141,7 @@ function hasFriends (callback) { }) } -function makeFriends (hosts, callback) { +function makeFriends (hosts: string[], callback: (err: Error) => void) { const podsScore = {} logger.info('Make friends!') @@ -141,7 +153,7 @@ function makeFriends (hosts, callback) { eachSeries(hosts, function (host, callbackEach) { computeForeignPodsList(host, podsScore, callbackEach) - }, function (err) { + }, function (err: Error) { if (err) return callback(err) logger.debug('Pods scores computed.', { podsScore: podsScore }) @@ -153,7 +165,7 @@ function makeFriends (hosts, callback) { }) } -function quitFriends (callback) { +function quitFriends (callback: (err: Error) => void) { // Stop pool requests requestScheduler.deactivate() @@ -172,7 +184,7 @@ function quitFriends (callback) { function announceIQuitMyFriends (pods, callbackAsync) { const requestParams = { - method: 'POST', + method: 'POST' as 'POST', path: '/api/' + API_VERSION + '/remote/pods/remove', sign: true, toPod: null @@ -199,7 +211,7 @@ function quitFriends (callback) { pod.destroy().asCallback(callbackEach) }, callbackAsync) } - ], function (err) { + ], function (err: Error) { // Don't forget to re activate the scheduler, even if there was an error requestScheduler.activate() @@ -210,7 +222,7 @@ function quitFriends (callback) { }) } -function sendOwnedVideosToPod (podId) { +function sendOwnedVideosToPod (podId: number) { db.Video.listOwnedAndPopulateAuthorAndTags(function (err, videosList) { if (err) { logger.error('Cannot get the list of videos we own.') @@ -229,7 +241,8 @@ function sendOwnedVideosToPod (podId) { type: 'add', endpoint: REQUEST_ENDPOINTS.VIDEOS, data: remoteVideo, - toIds: [ podId ] + toIds: [ podId ], + transaction: null } createRequest(options) }) @@ -272,7 +285,7 @@ export { // --------------------------------------------------------------------------- -function computeForeignPodsList (host, podsScore, callback) { +function computeForeignPodsList (host: string, podsScore: { [ host: string ]: number }, callback: (err: Error) => void) { getForeignPodsList(host, function (err, res) { if (err) return callback(err) @@ -288,11 +301,11 @@ function computeForeignPodsList (host, podsScore, callback) { else podsScore[foreignPodHost] = 1 }) - return callback() + return callback(null) }) } -function computeWinningPods (hosts, podsScore) { +function computeWinningPods (hosts: string[], podsScore: { [ host: string ]: number }) { // Build the list of pods to add // Only add a pod if it exists in more than a half base pods const podsList = [] @@ -308,7 +321,7 @@ function computeWinningPods (hosts, podsScore) { return podsList } -function getForeignPodsList (host, callback) { +function getForeignPodsList (host: string, callback: (err: Error, foreignPodsList?: any) => void) { const path = '/api/' + API_VERSION + '/pods' request.get(REMOTE_SCHEME.HTTP + '://' + host + path, function (err, response, body) { @@ -323,16 +336,16 @@ function getForeignPodsList (host, callback) { }) } -function makeRequestsToWinningPods (cert, podsList, callback) { +function makeRequestsToWinningPods (cert: string, podsList: PodInstance[], callback: (err: Error) => void) { // Stop pool requests requestScheduler.deactivate() // Flush pool requests requestScheduler.forceSend() - eachLimit(podsList, REQUESTS_IN_PARALLEL, function (pod: { host: string }, callbackEach) { + eachLimit(podsList, REQUESTS_IN_PARALLEL, function (pod: PodInstance, callbackEach) { const params = { url: REMOTE_SCHEME.HTTP + '://' + pod.host + '/api/' + API_VERSION + '/pods/', - method: 'POST', + method: 'POST' as 'POST', json: { host: CONFIG.WEBSERVER.HOST, email: CONFIG.ADMIN.EMAIL, @@ -371,15 +384,22 @@ function makeRequestsToWinningPods (cert, podsList, callback) { requestScheduler.activate() logger.debug('makeRequestsToWinningPods finished.') - return callback() + return callback(null) }) } // Wrapper that populate "toIds" argument with all our friends if it is not specified -// { type, endpoint, data, toIds, transaction } -function createRequest (options, callback?) { +type CreateRequestOptions = { + type: string + endpoint: string + data: Object + toIds?: number[] + transaction: Sequelize.Transaction +} +function createRequest (options: CreateRequestOptions, callback?: (err: Error) => void) { if (!callback) callback = function () { /* empty */ } - if (options.toIds) return requestScheduler.createRequest(options, callback) + + if (options.toIds !== undefined) return requestScheduler.createRequest(options as RequestSchedulerOptions, callback) // If the "toIds" pods is not specified, we send the request to all our friends db.Pod.listAllIds(options.transaction, function (err, podIds) { @@ -393,18 +413,18 @@ function createRequest (options, callback?) { }) } -function createVideoQaduRequest (options, callback) { +function createVideoQaduRequest (options: RequestVideoQaduSchedulerOptions, callback: (err: Error) => void) { if (!callback) callback = createEmptyCallback() requestVideoQaduScheduler.createRequest(options, callback) } -function createVideoEventRequest (options, callback) { +function createVideoEventRequest (options: RequestVideoEventSchedulerOptions, callback: (err: Error) => void) { if (!callback) callback = createEmptyCallback() requestVideoEventScheduler.createRequest(options, callback) } -function isMe (host) { +function isMe (host: string) { return host === CONFIG.WEBSERVER.HOST } diff --git a/server/lib/jobs/handlers/index.ts b/server/lib/jobs/handlers/index.ts index ae5440031..7d0263b15 100644 --- a/server/lib/jobs/handlers/index.ts +++ b/server/lib/jobs/handlers/index.ts @@ -1,6 +1,14 @@ import * as videoTranscoder from './video-transcoder' -const jobHandlers = { +import { VideoInstance } from '../../../models' + +export interface JobHandler { + process (data: object, callback: (err: Error, videoInstance?: T) => void) + onError (err: Error, jobId: number, video: T, callback: (err: Error) => void) + onSuccess (data: any, jobId: number, video: T, callback: (err: Error) => void) +} + +const jobHandlers: { [ handlerName: string ]: JobHandler } = { videoTranscoder } diff --git a/server/lib/jobs/handlers/video-transcoder.ts b/server/lib/jobs/handlers/video-transcoder.ts index 43599356a..efa18ef2d 100644 --- a/server/lib/jobs/handlers/video-transcoder.ts +++ b/server/lib/jobs/handlers/video-transcoder.ts @@ -1,8 +1,9 @@ import { database as db } from '../../../initializers/database' import { logger } from '../../../helpers' import { addVideoToFriends } from '../../../lib' +import { VideoInstance } from '../../../models' -function process (data, callback) { +function process (data: { id: string }, callback: (err: Error, videoInstance?: VideoInstance) => void) { db.Video.loadAndPopulateAuthorAndPodAndTags(data.id, function (err, video) { if (err) return callback(err) @@ -12,12 +13,12 @@ function process (data, callback) { }) } -function onError (err, jobId, video, callback) { +function onError (err: Error, jobId: number, video: VideoInstance, callback: () => void) { logger.error('Error when transcoding video file in job %d.', jobId, { error: err }) return callback() } -function onSuccess (data, jobId, video, callback) { +function onSuccess (data: any, jobId: number, video: VideoInstance, callback: (err: Error) => void) { logger.info('Job %d is a success.', jobId) video.toAddRemoteJSON(function (err, remoteVideo) { diff --git a/server/lib/jobs/job-scheduler.ts b/server/lib/jobs/job-scheduler.ts index ad5f7f6d9..2f01387e7 100644 --- a/server/lib/jobs/job-scheduler.ts +++ b/server/lib/jobs/job-scheduler.ts @@ -1,4 +1,5 @@ import { forever, queue } from 'async' +import * as Sequelize from 'sequelize' import { database as db } from '../../initializers/database' import { @@ -7,7 +8,10 @@ import { JOB_STATES } from '../../initializers' import { logger } from '../../helpers' -import { jobHandlers } from './handlers' +import { JobInstance } from '../../models' +import { JobHandler, jobHandlers } from './handlers' + +type JobQueueCallback = (err: Error) => void class JobScheduler { @@ -24,7 +28,7 @@ class JobScheduler { logger.info('Jobs scheduler activated.') - const jobsQueue = queue(this.processJob.bind(this)) + const jobsQueue = queue(this.processJob.bind(this)) // Finish processing jobs from a previous start const state = JOB_STATES.PROCESSING @@ -58,7 +62,7 @@ class JobScheduler { }) } - createJob (transaction, handlerName: string, handlerInputData: object, callback) { + createJob (transaction: Sequelize.Transaction, handlerName: string, handlerInputData: object, callback: (err: Error) => void) { const createQuery = { state: JOB_STATES.PENDING, handlerName, @@ -69,7 +73,7 @@ class JobScheduler { db.Job.create(createQuery, options).asCallback(callback) } - private enqueueJobs (err, jobsQueue, jobs) { + private enqueueJobs (err: Error, jobsQueue: AsyncQueue, jobs: JobInstance[]) { if (err) { logger.error('Cannot list pending jobs.', { error: err }) } else { @@ -79,7 +83,7 @@ class JobScheduler { } } - private processJob (job, callback) { + private processJob (job: JobInstance, callback: (err: Error) => void) { const jobHandler = jobHandlers[job.handlerName] logger.info('Processing job %d with handler %s.', job.id, job.handlerName) @@ -89,8 +93,8 @@ class JobScheduler { if (err) return this.cannotSaveJobError(err, callback) if (jobHandler === undefined) { - logger.error('Unknown job handler for job %s.', jobHandler.handlerName) - return callback() + logger.error('Unknown job handler for job %s.', job.handlerName) + return callback(null) } return jobHandler.process(job.handlerInputData, (err, result) => { @@ -104,7 +108,7 @@ class JobScheduler { }) } - private onJobError (jobHandler, job, jobResult, callback) { + private onJobError (jobHandler: JobHandler, job: JobInstance, jobResult: any, callback: (err: Error) => void) { job.state = JOB_STATES.ERROR job.save().asCallback(err => { @@ -114,7 +118,7 @@ class JobScheduler { }) } - private onJobSuccess (jobHandler, job, jobResult, callback) { + private onJobSuccess (jobHandler: JobHandler, job: JobInstance, jobResult: any, callback: (err: Error) => void) { job.state = JOB_STATES.SUCCESS job.save().asCallback(err => { @@ -124,7 +128,7 @@ class JobScheduler { }) } - private cannotSaveJobError (err, callback) { + private cannotSaveJobError (err: Error, callback: (err: Error) => void) { logger.error('Cannot save new job state.', { error: err }) return callback(err) } diff --git a/server/lib/oauth-model.ts b/server/lib/oauth-model.ts index 3bdf0f478..7cf42e94c 100644 --- a/server/lib/oauth-model.ts +++ b/server/lib/oauth-model.ts @@ -1,27 +1,30 @@ +import { OAuthClientInstance, UserInstance } from '../models' import { database as db } from '../initializers/database' import { logger } from '../helpers' +type TokenInfo = { accessToken: string, refreshToken: string, accessTokenExpiresAt: Date, refreshTokenExpiresAt: Date } + // --------------------------------------------------------------------------- -function getAccessToken (bearerToken) { +function getAccessToken (bearerToken: string) { logger.debug('Getting access token (bearerToken: ' + bearerToken + ').') return db.OAuthToken.getByTokenAndPopulateUser(bearerToken) } -function getClient (clientId, clientSecret) { +function getClient (clientId: string, clientSecret: string) { logger.debug('Getting Client (clientId: ' + clientId + ', clientSecret: ' + clientSecret + ').') return db.OAuthClient.getByIdAndSecret(clientId, clientSecret) } -function getRefreshToken (refreshToken) { +function getRefreshToken (refreshToken: string) { logger.debug('Getting RefreshToken (refreshToken: ' + refreshToken + ').') return db.OAuthToken.getByRefreshTokenAndPopulateClient(refreshToken) } -function getUser (username, password) { +function getUser (username: string, password: string) { logger.debug('Getting User (username: ' + username + ', password: ' + password + ').') return db.User.getByUsername(username).then(function (user) { @@ -42,7 +45,7 @@ function getUser (username, password) { }) } -function revokeToken (token) { +function revokeToken (token: TokenInfo) { return db.OAuthToken.getByRefreshTokenAndPopulateUser(token.refreshToken).then(function (tokenDB) { if (tokenDB) tokenDB.destroy() @@ -60,7 +63,7 @@ function revokeToken (token) { }) } -function saveToken (token, client, user) { +function saveToken (token: TokenInfo, client: OAuthClientInstance, user: UserInstance) { logger.debug('Saving token ' + token.accessToken + ' for client ' + client.id + ' and user ' + user.id + '.') const tokenToCreate = { 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' import { database as db } from '../../initializers/database' import { logger, makeSecureRequest } from '../../helpers' +import { PodInstance } from '../../models' import { API_VERSION, REQUESTS_IN_PARALLEL, @@ -9,11 +10,12 @@ import { } from '../../initializers' abstract class BaseRequestScheduler { + requestInterval: number + limitPods: number + limitPerPod: number + protected lastRequestTimestamp: number protected timer: NodeJS.Timer - protected requestInterval: number - protected limitPods: number - protected limitPerPod: number protected description: string constructor () { @@ -53,24 +55,24 @@ abstract class BaseRequestScheduler { return REQUESTS_INTERVAL - (Date.now() - this.lastRequestTimestamp) } - remainingRequestsCount (callback) { + remainingRequestsCount (callback: (err: Error, total: number) => void) { return this.getRequestModel().countTotalRequests(callback) } - flush (callback) { + flush (callback: (err: Error) => void) { this.getRequestModel().removeAll(callback) } // --------------------------------------------------------------------------- // Make a requests to friends of a certain type - protected makeRequest (toPod, requestEndpoint, requestsToMake, callback) { + protected makeRequest (toPod: PodInstance, requestEndpoint: string, requestsToMake: Object, callback) { if (!callback) callback = function () { /* empty */ } const params = { toPod: toPod, sign: true, // Prove our identity - method: 'POST', + method: 'POST' as 'POST', path: '/api/' + API_VERSION + '/remote/' + requestEndpoint, data: requestsToMake // Requests we need to make } diff --git a/server/lib/request/index.ts b/server/lib/request/index.ts index c98f956db..110d0ed78 100644 --- a/server/lib/request/index.ts +++ b/server/lib/request/index.ts @@ -1,3 +1,4 @@ +export * from './base-request-scheduler' export * from './request-scheduler' export * from './request-video-event-scheduler' export * from './request-video-qadu-scheduler' diff --git a/server/lib/request/request-scheduler.ts b/server/lib/request/request-scheduler.ts index 26ffbfb86..69d840eeb 100644 --- a/server/lib/request/request-scheduler.ts +++ b/server/lib/request/request-scheduler.ts @@ -1,3 +1,5 @@ +import * as Sequelize from 'sequelize' + import { database as db } from '../../initializers/database' import { BaseRequestScheduler } from './base-request-scheduler' import { logger } from '../../helpers' @@ -6,6 +8,14 @@ import { REQUESTS_LIMIT_PER_POD } from '../../initializers' +export type RequestSchedulerOptions = { + type: string + endpoint: string + data: Object + toIds: number[] + transaction: Sequelize.Transaction +} + class RequestScheduler extends BaseRequestScheduler { constructor () { super() @@ -25,7 +35,7 @@ class RequestScheduler extends BaseRequestScheduler { return db.RequestToPod } - buildRequestObjects (requests) { + buildRequestObjects (requests: { [ toPodId: number ]: any }) { const requestsToMakeGrouped = {} Object.keys(requests).forEach(toPodId => { @@ -51,14 +61,7 @@ class RequestScheduler extends BaseRequestScheduler { return requestsToMakeGrouped } - // { type, endpoint, data, toIds, transaction } - createRequest (options, callback) { - const type = options.type - const endpoint = options.endpoint - const data = options.data - const toIds = options.toIds - const transaction = options.transaction - + createRequest ({ type, endpoint, data, toIds, transaction }: RequestSchedulerOptions, callback: (err: Error) => void) { // TODO: check the setPods works const podIds = [] @@ -77,7 +80,7 @@ class RequestScheduler extends BaseRequestScheduler { } } - const dbRequestOptions = { + const dbRequestOptions: Sequelize.CreateOptions = { transaction } diff --git a/server/lib/request/request-video-event-scheduler.ts b/server/lib/request/request-video-event-scheduler.ts index bde50b1d3..9da82585e 100644 --- a/server/lib/request/request-video-event-scheduler.ts +++ b/server/lib/request/request-video-event-scheduler.ts @@ -1,3 +1,5 @@ +import * as Sequelize from 'sequelize' + import { database as db } from '../../initializers/database' import { BaseRequestScheduler } from './base-request-scheduler' import { @@ -6,6 +8,13 @@ import { REQUEST_VIDEO_EVENT_ENDPOINT } from '../../initializers' +export type RequestVideoEventSchedulerOptions = { + type: string + videoId: string + count?: number + transaction?: Sequelize.Transaction +} + class RequestVideoEventScheduler extends BaseRequestScheduler { constructor () { super() @@ -25,7 +34,7 @@ class RequestVideoEventScheduler extends BaseRequestScheduler { return db.RequestVideoEvent } - buildRequestObjects (eventsToProcess) { + buildRequestObjects (eventsToProcess: { [ toPodId: number ]: any }[]) { const requestsToMakeGrouped = {} /* Example: @@ -87,16 +96,10 @@ class RequestVideoEventScheduler extends BaseRequestScheduler { return requestsToMakeGrouped } - // { type, videoId, count?, transaction? } - createRequest (options, callback) { - const type = options.type - const videoId = options.videoId - const transaction = options.transaction - let count = options.count - + createRequest ({ type, videoId, count, transaction }: RequestVideoEventSchedulerOptions, callback: (err: Error) => void) { if (count === undefined) count = 1 - const dbRequestOptions: { transaction?: any } = {} + const dbRequestOptions: Sequelize.CreateOptions = {} if (transaction) dbRequestOptions.transaction = transaction const createQuery = { diff --git a/server/lib/request/request-video-qadu-scheduler.ts b/server/lib/request/request-video-qadu-scheduler.ts index dab526088..436fd8e50 100644 --- a/server/lib/request/request-video-qadu-scheduler.ts +++ b/server/lib/request/request-video-qadu-scheduler.ts @@ -1,3 +1,5 @@ +import * as Sequelize from 'sequelize' + import { database as db } from '../../initializers/database' import { BaseRequestScheduler } from './base-request-scheduler' import { logger } from '../../helpers' @@ -8,6 +10,12 @@ import { REQUEST_VIDEO_QADU_TYPES } from '../../initializers' +export type RequestVideoQaduSchedulerOptions = { + type: string + videoId: string + transaction?: Sequelize.Transaction +} + class RequestVideoQaduScheduler extends BaseRequestScheduler { constructor () { super() @@ -27,7 +35,7 @@ class RequestVideoQaduScheduler extends BaseRequestScheduler { return db.RequestVideoQadu } - buildRequestObjects (requests) { + buildRequestObjects (requests: { [ toPodId: number ]: any }[]) { const requestsToMakeGrouped = {} Object.keys(requests).forEach(toPodId => { @@ -96,17 +104,12 @@ class RequestVideoQaduScheduler extends BaseRequestScheduler { return requestsToMakeGrouped } - // { type, videoId, transaction? } - createRequest (options, callback) { - const type = options.type - const videoId = options.videoId - const transaction = options.transaction - - const dbRequestOptions: { transaction?: any } = {} + createRequest ({ type, videoId, transaction }: RequestVideoQaduSchedulerOptions, callback: (err: Error) => void) { + const dbRequestOptions: Sequelize.BulkCreateOptions = {} if (transaction) dbRequestOptions.transaction = transaction // Send the update to all our friends - db.Pod.listAllIds(options.transaction, function (err, podIds) { + db.Pod.listAllIds(transaction, function (err, podIds) { if (err) return callback(err) const queries = [] -- cgit v1.2.3