aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/job-queue/handlers/transcoding-job-builder.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/job-queue/handlers/transcoding-job-builder.ts')
-rw-r--r--server/lib/job-queue/handlers/transcoding-job-builder.ts47
1 files changed, 47 insertions, 0 deletions
diff --git a/server/lib/job-queue/handlers/transcoding-job-builder.ts b/server/lib/job-queue/handlers/transcoding-job-builder.ts
new file mode 100644
index 000000000..8b4a877d7
--- /dev/null
+++ b/server/lib/job-queue/handlers/transcoding-job-builder.ts
@@ -0,0 +1,47 @@
1import { Job } from 'bullmq'
2import { createOptimizeOrMergeAudioJobs } from '@server/lib/transcoding/create-transcoding-job'
3import { UserModel } from '@server/models/user/user'
4import { VideoModel } from '@server/models/video/video'
5import { VideoJobInfoModel } from '@server/models/video/video-job-info'
6import { pick } from '@shared/core-utils'
7import { TranscodingJobBuilderPayload } from '@shared/models'
8import { logger } from '../../../helpers/logger'
9import { JobQueue } from '../job-queue'
10
11async function processTranscodingJobBuilder (job: Job) {
12 const payload = job.data as TranscodingJobBuilderPayload
13
14 logger.info('Processing transcoding job builder in job %s.', job.id)
15
16 if (payload.optimizeJob) {
17 const video = await VideoModel.loadFull(payload.videoUUID)
18 const user = await UserModel.loadByVideoId(video.id)
19 const videoFile = video.getMaxQualityFile()
20
21 await createOptimizeOrMergeAudioJobs({
22 ...pick(payload.optimizeJob, [ 'isNewVideo' ]),
23
24 video,
25 videoFile,
26 user
27 })
28 }
29
30 for (const job of (payload.jobs || [])) {
31 await JobQueue.Instance.createJob(job)
32
33 await VideoJobInfoModel.increaseOrCreate(payload.videoUUID, 'pendingTranscode')
34 }
35
36 for (const sequentialJobs of (payload.sequentialJobs || [])) {
37 await JobQueue.Instance.createSequentialJobFlow(...sequentialJobs)
38
39 await VideoJobInfoModel.increaseOrCreate(payload.videoUUID, 'pendingTranscode', sequentialJobs.length)
40 }
41}
42
43// ---------------------------------------------------------------------------
44
45export {
46 processTranscodingJobBuilder
47}