From a6e37eebfbef9aef91e35173ed799afb6c4a288b Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 5 May 2021 09:25:11 +0200 Subject: Fix transcoding job priority New resolution jobs are also important if waiting for transcoding is enabled since we publish the video after the first resolution generation --- server/initializers/constants.ts | 5 +---- server/lib/job-queue/handlers/video-transcoding.ts | 6 +++--- server/lib/video.ts | 8 ++++---- server/tests/api/videos/video-transcoder.ts | 7 +------ 4 files changed, 9 insertions(+), 17 deletions(-) (limited to 'server') diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index 37a963760..d390fd95e 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts @@ -188,10 +188,7 @@ const REPEAT_JOBS: { [ id: string ]: EveryRepeatOptions | CronRepeatOptions } = } } const JOB_PRIORITY = { - TRANSCODING: { - OPTIMIZER: 10, - NEW_RESOLUTION: 100 - } + TRANSCODING: 100 } const BROADCAST_CONCURRENCY = 30 // How many requests in parallel we do in activitypub-http-broadcast job diff --git a/server/lib/job-queue/handlers/video-transcoding.ts b/server/lib/job-queue/handlers/video-transcoding.ts index 4ee2b2df2..dbf412fbb 100644 --- a/server/lib/job-queue/handlers/video-transcoding.ts +++ b/server/lib/job-queue/handlers/video-transcoding.ts @@ -1,7 +1,7 @@ import * as Bull from 'bull' import { TranscodeOptionsType } from '@server/helpers/ffmpeg-utils' import { JOB_PRIORITY } from '@server/initializers/constants' -import { getJobTranscodingPriorityMalus, publishAndFederateIfNeeded } from '@server/lib/video' +import { getTranscodingJobPriority, publishAndFederateIfNeeded } from '@server/lib/video' import { getVideoFilePath } from '@server/lib/video-paths' import { UserModel } from '@server/models/account/user' import { MUser, MUserId, MVideoFullLight, MVideoUUID, MVideoWithFile } from '@server/types/models' @@ -215,7 +215,7 @@ async function createHlsJobIfEnabled (user: MUserId, payload: { if (!payload || CONFIG.TRANSCODING.HLS.ENABLED !== true) return false const jobOptions = { - priority: JOB_PRIORITY.TRANSCODING.NEW_RESOLUTION + await getJobTranscodingPriorityMalus(user) + priority: await getTranscodingJobPriority(user) } const hlsTranscodingPayload: HLSTranscodingPayload = { @@ -272,7 +272,7 @@ async function createLowerResolutionsJobs ( resolutionCreated.push(resolution) const jobOptions = { - priority: JOB_PRIORITY.TRANSCODING.NEW_RESOLUTION + await getJobTranscodingPriorityMalus(user) + priority: await getTranscodingJobPriority(user) } JobQueue.Instance.createJob({ type: 'video-transcoding', payload: dataInput }, jobOptions) diff --git a/server/lib/video.ts b/server/lib/video.ts index e381e0a69..9469b8178 100644 --- a/server/lib/video.ts +++ b/server/lib/video.ts @@ -121,19 +121,19 @@ async function addOptimizeOrMergeAudioJob (video: MVideo, videoFile: MVideoFile, } const jobOptions = { - priority: JOB_PRIORITY.TRANSCODING.OPTIMIZER + await getJobTranscodingPriorityMalus(user) + priority: await getTranscodingJobPriority(user) } return JobQueue.Instance.createJobWithPromise({ type: 'video-transcoding', payload: dataInput }, jobOptions) } -async function getJobTranscodingPriorityMalus (user: MUserId) { +async function getTranscodingJobPriority (user: MUserId) { const now = new Date() const lastWeek = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 7) const videoUploadedByUser = await VideoModel.countVideosUploadedByUserSince(user.id, lastWeek) - return videoUploadedByUser + return JOB_PRIORITY.TRANSCODING + videoUploadedByUser } // --------------------------------------------------------------------------- @@ -144,5 +144,5 @@ export { buildVideoThumbnailsFromReq, setVideoTags, addOptimizeOrMergeAudioJob, - getJobTranscodingPriorityMalus + getTranscodingJobPriority } diff --git a/server/tests/api/videos/video-transcoder.ts b/server/tests/api/videos/video-transcoder.ts index 1058baaa3..1c99f26df 100644 --- a/server/tests/api/videos/video-transcoder.ts +++ b/server/tests/api/videos/video-transcoder.ts @@ -721,12 +721,7 @@ describe('Test video transcoding', function () { expect(webtorrentJobs).to.have.lengthOf(6) expect(optimizeJobs).to.have.lengthOf(1) - for (const j of optimizeJobs) { - expect(j.priority).to.be.greaterThan(11) - expect(j.priority).to.be.lessThan(50) - } - - for (const j of hlsJobs.concat(webtorrentJobs)) { + for (const j of optimizeJobs.concat(hlsJobs.concat(webtorrentJobs))) { expect(j.priority).to.be.greaterThan(100) expect(j.priority).to.be.lessThan(150) } -- cgit v1.2.3