diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/initializers/constants.ts | 5 | ||||
-rw-r--r-- | server/lib/job-queue/handlers/video-transcoding.ts | 6 | ||||
-rw-r--r-- | server/lib/video.ts | 8 | ||||
-rw-r--r-- | server/tests/api/videos/video-transcoder.ts | 7 |
4 files changed, 9 insertions, 17 deletions
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 } = | |||
188 | } | 188 | } |
189 | } | 189 | } |
190 | const JOB_PRIORITY = { | 190 | const JOB_PRIORITY = { |
191 | TRANSCODING: { | 191 | TRANSCODING: 100 |
192 | OPTIMIZER: 10, | ||
193 | NEW_RESOLUTION: 100 | ||
194 | } | ||
195 | } | 192 | } |
196 | 193 | ||
197 | const BROADCAST_CONCURRENCY = 30 // How many requests in parallel we do in activitypub-http-broadcast job | 194 | 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 @@ | |||
1 | import * as Bull from 'bull' | 1 | import * as Bull from 'bull' |
2 | import { TranscodeOptionsType } from '@server/helpers/ffmpeg-utils' | 2 | import { TranscodeOptionsType } from '@server/helpers/ffmpeg-utils' |
3 | import { JOB_PRIORITY } from '@server/initializers/constants' | 3 | import { JOB_PRIORITY } from '@server/initializers/constants' |
4 | import { getJobTranscodingPriorityMalus, publishAndFederateIfNeeded } from '@server/lib/video' | 4 | import { getTranscodingJobPriority, publishAndFederateIfNeeded } from '@server/lib/video' |
5 | import { getVideoFilePath } from '@server/lib/video-paths' | 5 | import { getVideoFilePath } from '@server/lib/video-paths' |
6 | import { UserModel } from '@server/models/account/user' | 6 | import { UserModel } from '@server/models/account/user' |
7 | import { MUser, MUserId, MVideoFullLight, MVideoUUID, MVideoWithFile } from '@server/types/models' | 7 | import { MUser, MUserId, MVideoFullLight, MVideoUUID, MVideoWithFile } from '@server/types/models' |
@@ -215,7 +215,7 @@ async function createHlsJobIfEnabled (user: MUserId, payload: { | |||
215 | if (!payload || CONFIG.TRANSCODING.HLS.ENABLED !== true) return false | 215 | if (!payload || CONFIG.TRANSCODING.HLS.ENABLED !== true) return false |
216 | 216 | ||
217 | const jobOptions = { | 217 | const jobOptions = { |
218 | priority: JOB_PRIORITY.TRANSCODING.NEW_RESOLUTION + await getJobTranscodingPriorityMalus(user) | 218 | priority: await getTranscodingJobPriority(user) |
219 | } | 219 | } |
220 | 220 | ||
221 | const hlsTranscodingPayload: HLSTranscodingPayload = { | 221 | const hlsTranscodingPayload: HLSTranscodingPayload = { |
@@ -272,7 +272,7 @@ async function createLowerResolutionsJobs ( | |||
272 | resolutionCreated.push(resolution) | 272 | resolutionCreated.push(resolution) |
273 | 273 | ||
274 | const jobOptions = { | 274 | const jobOptions = { |
275 | priority: JOB_PRIORITY.TRANSCODING.NEW_RESOLUTION + await getJobTranscodingPriorityMalus(user) | 275 | priority: await getTranscodingJobPriority(user) |
276 | } | 276 | } |
277 | 277 | ||
278 | JobQueue.Instance.createJob({ type: 'video-transcoding', payload: dataInput }, jobOptions) | 278 | 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, | |||
121 | } | 121 | } |
122 | 122 | ||
123 | const jobOptions = { | 123 | const jobOptions = { |
124 | priority: JOB_PRIORITY.TRANSCODING.OPTIMIZER + await getJobTranscodingPriorityMalus(user) | 124 | priority: await getTranscodingJobPriority(user) |
125 | } | 125 | } |
126 | 126 | ||
127 | return JobQueue.Instance.createJobWithPromise({ type: 'video-transcoding', payload: dataInput }, jobOptions) | 127 | return JobQueue.Instance.createJobWithPromise({ type: 'video-transcoding', payload: dataInput }, jobOptions) |
128 | } | 128 | } |
129 | 129 | ||
130 | async function getJobTranscodingPriorityMalus (user: MUserId) { | 130 | async function getTranscodingJobPriority (user: MUserId) { |
131 | const now = new Date() | 131 | const now = new Date() |
132 | const lastWeek = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 7) | 132 | const lastWeek = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 7) |
133 | 133 | ||
134 | const videoUploadedByUser = await VideoModel.countVideosUploadedByUserSince(user.id, lastWeek) | 134 | const videoUploadedByUser = await VideoModel.countVideosUploadedByUserSince(user.id, lastWeek) |
135 | 135 | ||
136 | return videoUploadedByUser | 136 | return JOB_PRIORITY.TRANSCODING + videoUploadedByUser |
137 | } | 137 | } |
138 | 138 | ||
139 | // --------------------------------------------------------------------------- | 139 | // --------------------------------------------------------------------------- |
@@ -144,5 +144,5 @@ export { | |||
144 | buildVideoThumbnailsFromReq, | 144 | buildVideoThumbnailsFromReq, |
145 | setVideoTags, | 145 | setVideoTags, |
146 | addOptimizeOrMergeAudioJob, | 146 | addOptimizeOrMergeAudioJob, |
147 | getJobTranscodingPriorityMalus | 147 | getTranscodingJobPriority |
148 | } | 148 | } |
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 () { | |||
721 | expect(webtorrentJobs).to.have.lengthOf(6) | 721 | expect(webtorrentJobs).to.have.lengthOf(6) |
722 | expect(optimizeJobs).to.have.lengthOf(1) | 722 | expect(optimizeJobs).to.have.lengthOf(1) |
723 | 723 | ||
724 | for (const j of optimizeJobs) { | 724 | for (const j of optimizeJobs.concat(hlsJobs.concat(webtorrentJobs))) { |
725 | expect(j.priority).to.be.greaterThan(11) | ||
726 | expect(j.priority).to.be.lessThan(50) | ||
727 | } | ||
728 | |||
729 | for (const j of hlsJobs.concat(webtorrentJobs)) { | ||
730 | expect(j.priority).to.be.greaterThan(100) | 725 | expect(j.priority).to.be.greaterThan(100) |
731 | expect(j.priority).to.be.lessThan(150) | 726 | expect(j.priority).to.be.lessThan(150) |
732 | } | 727 | } |