From a15871560f80e07386c1dabb8370cd2664ecfd1f Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 31 Jan 2020 16:56:52 +0100 Subject: Move to eslint --- server/lib/job-queue/job-queue.ts | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) (limited to 'server/lib/job-queue/job-queue.ts') diff --git a/server/lib/job-queue/job-queue.ts b/server/lib/job-queue/job-queue.ts index 61f07c487..14acace7d 100644 --- a/server/lib/job-queue/job-queue.ts +++ b/server/lib/job-queue/job-queue.ts @@ -28,7 +28,7 @@ type CreateJobArgument = { type: 'videos-views', payload: {} } | { type: 'video-redundancy', payload: VideoRedundancyPayload } -const handlers: { [ id in JobType ]: (job: Bull.Job) => Promise} = { +const handlers: { [id in JobType]: (job: Bull.Job) => Promise } = { 'activitypub-http-broadcast': processActivityPubHttpBroadcast, 'activitypub-http-unicast': processActivityPubHttpUnicast, 'activitypub-http-fetcher': processActivityPubHttpFetcher, @@ -60,13 +60,14 @@ class JobQueue { private static instance: JobQueue - private queues: { [ id in JobType ]?: Bull.Queue } = {} + private queues: { [id in JobType]?: Bull.Queue } = {} private initialized = false private jobRedisPrefix: string - private constructor () {} + private constructor () { + } - async init () { + init () { // Already initialized if (this.initialized === true) return this.initialized = true @@ -108,11 +109,16 @@ class JobQueue { } } - createJob (obj: CreateJobArgument) { + createJob (obj: CreateJobArgument): void { + this.createJobWithPromise(obj) + .catch(err => logger.error('Cannot create job.', { err, obj })) + } + + createJobWithPromise (obj: CreateJobArgument) { const queue = this.queues[obj.type] if (queue === undefined) { logger.error('Unknown queue %s: cannot create job.', obj.type) - throw Error('Unknown queue, cannot create job') + return } const jobArgs: Bull.JobOptions = { @@ -125,10 +131,10 @@ class JobQueue { } async listForApi (options: { - state: JobState, - start: number, - count: number, - asc?: boolean, + state: JobState + start: number + count: number + asc?: boolean jobType: JobType }): Promise { const { state, start, count, asc, jobType } = options @@ -137,7 +143,7 @@ class JobQueue { const filteredJobTypes = this.filterJobTypes(jobType) for (const jobType of filteredJobTypes) { - const queue = this.queues[ jobType ] + const queue = this.queues[jobType] if (queue === undefined) { logger.error('Unknown queue %s to list jobs.', jobType) continue @@ -165,7 +171,7 @@ class JobQueue { const filteredJobTypes = this.filterJobTypes(jobType) for (const type of filteredJobTypes) { - const queue = this.queues[ type ] + const queue = this.queues[type] if (queue === undefined) { logger.error('Unknown queue %s to count jobs.', type) continue @@ -173,7 +179,7 @@ class JobQueue { const counts = await queue.getJobCounts() - total += counts[ state ] + total += counts[state] } return total @@ -189,7 +195,7 @@ class JobQueue { private addRepeatableJobs () { this.queues['videos-views'].add({}, { repeat: REPEAT_JOBS['videos-views'] - }) + }).catch(err => logger.error('Cannot add repeatable job.', { err })) } private filterJobTypes (jobType?: JobType) { -- cgit v1.2.3