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
pull/4042/head
Chocobozzz 2021-05-05 09:25:11 +02:00
parent 494e60804d
commit a6e37eebfb
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
4 changed files with 9 additions and 17 deletions

View File

@ -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

View File

@ -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)

View File

@ -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
}

View File

@ -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)
}