mirror of https://github.com/Chocobozzz/PeerTube
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 generationpull/4042/head
parent
494e60804d
commit
a6e37eebfb
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue