From 402145b8630d1908c35f8c22846ddc4475f25d3e Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 14 Dec 2020 12:00:35 +0100 Subject: Refactor jobs state --- server/lib/job-queue/job-queue.ts | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'server/lib') diff --git a/server/lib/job-queue/job-queue.ts b/server/lib/job-queue/job-queue.ts index 49f06584d..5d0b797b0 100644 --- a/server/lib/job-queue/job-queue.ts +++ b/server/lib/job-queue/job-queue.ts @@ -1,4 +1,6 @@ import * as Bull from 'bull' +import { jobStates } from '@server/helpers/custom-validators/jobs' +import { processVideoRedundancy } from '@server/lib/job-queue/handlers/video-redundancy' import { ActivitypubFollowPayload, ActivitypubHttpBroadcastPayload, @@ -15,20 +17,19 @@ import { VideoTranscodingPayload } from '../../../shared/models' import { logger } from '../../helpers/logger' -import { Redis } from '../redis' import { JOB_ATTEMPTS, JOB_COMPLETED_LIFETIME, JOB_CONCURRENCY, JOB_TTL, REPEAT_JOBS, WEBSERVER } from '../../initializers/constants' +import { Redis } from '../redis' +import { processActivityPubFollow } from './handlers/activitypub-follow' import { processActivityPubHttpBroadcast } from './handlers/activitypub-http-broadcast' import { processActivityPubHttpFetcher } from './handlers/activitypub-http-fetcher' import { processActivityPubHttpUnicast } from './handlers/activitypub-http-unicast' -import { processEmail } from './handlers/email' -import { processVideoTranscoding } from './handlers/video-transcoding' -import { processActivityPubFollow } from './handlers/activitypub-follow' -import { processVideoImport } from './handlers/video-import' -import { processVideosViews } from './handlers/video-views' import { refreshAPObject } from './handlers/activitypub-refresher' +import { processEmail } from './handlers/email' import { processVideoFileImport } from './handlers/video-file-import' -import { processVideoRedundancy } from '@server/lib/job-queue/handlers/video-redundancy' +import { processVideoImport } from './handlers/video-import' import { processVideoLiveEnding } from './handlers/video-live-ending' +import { processVideoTranscoding } from './handlers/video-transcoding' +import { processVideosViews } from './handlers/video-views' type CreateJobArgument = { type: 'activitypub-http-broadcast', payload: ActivitypubHttpBroadcastPayload } | @@ -154,13 +155,15 @@ class JobQueue { } async listForApi (options: { - state: JobState | JobState[] + state?: JobState start: number count: number asc?: boolean jobType: JobType }): Promise { - const { state = Array.isArray(options.state) ? options.state : [ options.state ], start, count, asc, jobType } = options + const { state, start, count, asc, jobType } = options + + const states = state ? [ state ] : jobStates let results: Bull.Job[] = [] const filteredJobTypes = this.filterJobTypes(jobType) @@ -172,7 +175,7 @@ class JobQueue { continue } - const jobs = await queue.getJobs(state as Bull.JobStatus[], 0, start + count, asc) + const jobs = await queue.getJobs(states, 0, start + count, asc) results = results.concat(jobs) } @@ -188,8 +191,8 @@ class JobQueue { return results.slice(start, start + count) } - async count (state: JobState | JobState[], jobType?: JobType): Promise { - const states = Array.isArray(state) ? state : [ state ] + async count (state: JobState, jobType?: JobType): Promise { + const states = state ? [ state ] : jobStates let total = 0 const filteredJobTypes = this.filterJobTypes(jobType) -- cgit v1.2.3