diff options
Diffstat (limited to 'server/lib/jobs/transcoding-job-scheduler')
4 files changed, 0 insertions, 162 deletions
diff --git a/server/lib/jobs/transcoding-job-scheduler/index.ts b/server/lib/jobs/transcoding-job-scheduler/index.ts deleted file mode 100644 index 73152a1be..000000000 --- a/server/lib/jobs/transcoding-job-scheduler/index.ts +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | export * from './transcoding-job-scheduler' | ||
diff --git a/server/lib/jobs/transcoding-job-scheduler/transcoding-job-scheduler.ts b/server/lib/jobs/transcoding-job-scheduler/transcoding-job-scheduler.ts deleted file mode 100644 index e5530a73c..000000000 --- a/server/lib/jobs/transcoding-job-scheduler/transcoding-job-scheduler.ts +++ /dev/null | |||
@@ -1,23 +0,0 @@ | |||
1 | import { JobCategory } from '../../../../shared' | ||
2 | import { VideoModel } from '../../../models/video/video' | ||
3 | import { JobHandler, JobScheduler } from '../job-scheduler' | ||
4 | |||
5 | import * as videoFileOptimizer from './video-file-optimizer-handler' | ||
6 | import * as videoFileTranscoder from './video-file-transcoder-handler' | ||
7 | |||
8 | type TranscodingJobPayload = { | ||
9 | videoUUID: string | ||
10 | resolution?: number | ||
11 | } | ||
12 | const jobHandlers: { [ handlerName: string ]: JobHandler<TranscodingJobPayload, VideoModel> } = { | ||
13 | videoFileOptimizer, | ||
14 | videoFileTranscoder | ||
15 | } | ||
16 | const jobCategory: JobCategory = 'transcoding' | ||
17 | |||
18 | const transcodingJobScheduler = new JobScheduler(jobCategory, jobHandlers) | ||
19 | |||
20 | export { | ||
21 | TranscodingJobPayload, | ||
22 | transcodingJobScheduler | ||
23 | } | ||
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 @@ | |||
1 | import * as Bluebird from 'bluebird' | ||
2 | import { VideoPrivacy } from '../../../../shared/models/videos' | ||
3 | import { logger } from '../../../helpers/logger' | ||
4 | import { computeResolutionsToTranscode } from '../../../helpers/utils' | ||
5 | import { sequelizeTypescript } from '../../../initializers' | ||
6 | import { JobModel } from '../../../models/job/job' | ||
7 | import { VideoModel } from '../../../models/video/video' | ||
8 | import { shareVideoByServerAndChannel } from '../../activitypub' | ||
9 | import { sendCreateVideo } from '../../activitypub/send' | ||
10 | import { JobScheduler } from '../job-scheduler' | ||
11 | import { TranscodingJobPayload } from './transcoding-job-scheduler' | ||
12 | |||
13 | async 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 | |||
26 | function onError (err: Error, jobId: number) { | ||
27 | logger.error('Error when optimized video file in job %d.', jobId, err) | ||
28 | return Promise.resolve() | ||
29 | } | ||
30 | |||
31 | async 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 | |||
86 | export { | ||
87 | process, | ||
88 | onError, | ||
89 | onSuccess | ||
90 | } | ||
diff --git a/server/lib/jobs/transcoding-job-scheduler/video-file-transcoder-handler.ts b/server/lib/jobs/transcoding-job-scheduler/video-file-transcoder-handler.ts deleted file mode 100644 index 883d3eba8..000000000 --- a/server/lib/jobs/transcoding-job-scheduler/video-file-transcoder-handler.ts +++ /dev/null | |||
@@ -1,48 +0,0 @@ | |||
1 | import { VideoResolution } from '../../../../shared' | ||
2 | import { VideoPrivacy } from '../../../../shared/models/videos' | ||
3 | import { logger } from '../../../helpers/logger' | ||
4 | import { VideoModel } from '../../../models/video/video' | ||
5 | import { sendUpdateVideo } from '../../activitypub/send' | ||
6 | |||
7 | async function process (data: { videoUUID: string, resolution: VideoResolution }, jobId: number) { | ||
8 | const video = await VideoModel.loadByUUIDAndPopulateAccountAndServerAndTags(data.videoUUID) | ||
9 | // No video, maybe deleted? | ||
10 | if (!video) { | ||
11 | logger.info('Do not process job %d, video does not exist.', jobId, { videoUUID: video.uuid }) | ||
12 | return undefined | ||
13 | } | ||
14 | |||
15 | await video.transcodeOriginalVideofile(data.resolution) | ||
16 | |||
17 | return video | ||
18 | } | ||
19 | |||
20 | function onError (err: Error, jobId: number) { | ||
21 | logger.error('Error when transcoding video file in job %d.', jobId, err) | ||
22 | return Promise.resolve() | ||
23 | } | ||
24 | |||
25 | async function onSuccess (jobId: number, video: VideoModel) { | ||
26 | if (video === undefined) return undefined | ||
27 | |||
28 | logger.info('Job %d is a success.', jobId) | ||
29 | |||
30 | // Maybe the video changed in database, refresh it | ||
31 | const videoDatabase = await VideoModel.loadByUUIDAndPopulateAccountAndServerAndTags(video.uuid) | ||
32 | // Video does not exist anymore | ||
33 | if (!videoDatabase) return undefined | ||
34 | |||
35 | if (video.privacy !== VideoPrivacy.PRIVATE) { | ||
36 | await sendUpdateVideo(video, undefined) | ||
37 | } | ||
38 | |||
39 | return undefined | ||
40 | } | ||
41 | |||
42 | // --------------------------------------------------------------------------- | ||
43 | |||
44 | export { | ||
45 | process, | ||
46 | onError, | ||
47 | onSuccess | ||
48 | } | ||