aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/jobs/transcoding-job-scheduler/video-file-optimizer-handler.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/jobs/transcoding-job-scheduler/video-file-optimizer-handler.ts')
-rw-r--r--server/lib/jobs/transcoding-job-scheduler/video-file-optimizer-handler.ts90
1 files changed, 0 insertions, 90 deletions
diff --git a/server/lib/jobs/transcoding-job-scheduler/video-file-optimizer-handler.ts b/server/lib/jobs/transcoding-job-scheduler/video-file-optimizer-handler.ts
deleted file mode 100644
index f224a31b4..000000000
--- a/server/lib/jobs/transcoding-job-scheduler/video-file-optimizer-handler.ts
+++ /dev/null
@@ -1,90 +0,0 @@
1import * as Bluebird from 'bluebird'
2import { VideoPrivacy } from '../../../../shared/models/videos'
3import { logger } from '../../../helpers/logger'
4import { computeResolutionsToTranscode } from '../../../helpers/utils'
5import { sequelizeTypescript } from '../../../initializers'
6import { JobModel } from '../../../models/job/job'
7import { VideoModel } from '../../../models/video/video'
8import { shareVideoByServerAndChannel } from '../../activitypub'
9import { sendCreateVideo } from '../../activitypub/send'
10import { JobScheduler } from '../job-scheduler'
11import { TranscodingJobPayload } from './transcoding-job-scheduler'
12
13async function process (data: TranscodingJobPayload, jobId: number) {
14 const video = await VideoModel.loadByUUIDAndPopulateAccountAndServerAndTags(data.videoUUID)
15 // No video, maybe deleted?
16 if (!video) {
17 logger.info('Do not process job %d, video does not exist.', jobId, { videoUUID: video.uuid })
18 return undefined
19 }
20
21 await video.optimizeOriginalVideofile()
22
23 return video
24}
25
26function onError (err: Error, jobId: number) {
27 logger.error('Error when optimized video file in job %d.', jobId, err)
28 return Promise.resolve()
29}
30
31async function onSuccess (jobId: number, video: VideoModel, jobScheduler: JobScheduler<TranscodingJobPayload, VideoModel>) {
32 if (video === undefined) return undefined
33
34 logger.info('Job %d is a success.', jobId)
35
36 // Maybe the video changed in database, refresh it
37 const videoDatabase = await VideoModel.loadByUUIDAndPopulateAccountAndServerAndTags(video.uuid)
38 // Video does not exist anymore
39 if (!videoDatabase) return undefined
40
41 if (video.privacy !== VideoPrivacy.PRIVATE) {
42 // Now we'll add the video's meta data to our followers
43 await sendCreateVideo(video, undefined)
44 await shareVideoByServerAndChannel(video, undefined)
45 }
46
47 const originalFileHeight = await videoDatabase.getOriginalFileHeight()
48
49 // Create transcoding jobs if there are enabled resolutions
50 const resolutionsEnabled = computeResolutionsToTranscode(originalFileHeight)
51 logger.info(
52 'Resolutions computed for video %s and origin file height of %d.', videoDatabase.uuid, originalFileHeight,
53 { resolutions: resolutionsEnabled }
54 )
55
56 if (resolutionsEnabled.length !== 0) {
57 try {
58 await sequelizeTypescript.transaction(async t => {
59 const tasks: Bluebird<JobModel>[] = []
60
61 for (const resolution of resolutionsEnabled) {
62 const dataInput = {
63 videoUUID: videoDatabase.uuid,
64 resolution
65 }
66
67 const p = jobScheduler.createJob(t, 'videoFileTranscoder', dataInput)
68 tasks.push(p)
69 }
70
71 await Promise.all(tasks)
72 })
73
74 logger.info('Transcoding jobs created for uuid %s.', videoDatabase.uuid, { resolutionsEnabled })
75 } catch (err) {
76 logger.warn('Cannot transcode the video.', err)
77 }
78 } else {
79 logger.info('No transcoding jobs created for video %s (no resolutions enabled).')
80 return undefined
81 }
82}
83
84// ---------------------------------------------------------------------------
85
86export {
87 process,
88 onError,
89 onSuccess
90}