ActivityPub-federated video streaming platform using P2P directly in your web browser
Fix transcoding job priority
Chocobozzza6e37eebfbef
diff --git a/server/initializers/constants.ts b/server/initializers/constants.tsindex 37a9637608..d390fd95e9 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 jobdiff --git a/server/lib/job-queue/handlers/video-transcoding.ts b/server/lib/job-queue/handlers/video-transcoding.tsindex 4ee2b2df22..dbf412fbbe 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 falseconst 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.tsindex e381e0a699..9469b81789 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.tsindex 1058baaa31..1c99f26df2 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)}