diff options
Diffstat (limited to 'server/lib/job-queue/handlers/video-transcoding.ts')
-rw-r--r-- | server/lib/job-queue/handlers/video-transcoding.ts | 34 |
1 files changed, 5 insertions, 29 deletions
diff --git a/server/lib/job-queue/handlers/video-transcoding.ts b/server/lib/job-queue/handlers/video-transcoding.ts index ceee83f13..d9dad795e 100644 --- a/server/lib/job-queue/handlers/video-transcoding.ts +++ b/server/lib/job-queue/handlers/video-transcoding.ts | |||
@@ -5,10 +5,10 @@ import { VideoModel } from '../../../models/video/video' | |||
5 | import { JobQueue } from '../job-queue' | 5 | import { JobQueue } from '../job-queue' |
6 | import { federateVideoIfNeeded } from '../../activitypub' | 6 | import { federateVideoIfNeeded } from '../../activitypub' |
7 | import { retryTransactionWrapper } from '../../../helpers/database-utils' | 7 | import { retryTransactionWrapper } from '../../../helpers/database-utils' |
8 | import { sequelizeTypescript, CONFIG } from '../../../initializers' | 8 | import { CONFIG, sequelizeTypescript } from '../../../initializers' |
9 | import * as Bluebird from 'bluebird' | 9 | import * as Bluebird from 'bluebird' |
10 | import { computeResolutionsToTranscode } from '../../../helpers/ffmpeg-utils' | 10 | import { computeResolutionsToTranscode } from '../../../helpers/ffmpeg-utils' |
11 | import { generateHlsPlaylist, importVideoFile, optimizeVideofile, transcodeOriginalVideofile } from '../../video-transcoding' | 11 | import { generateHlsPlaylist, optimizeVideofile, transcodeOriginalVideofile } from '../../video-transcoding' |
12 | import { Notifier } from '../../notifier' | 12 | import { Notifier } from '../../notifier' |
13 | 13 | ||
14 | export type VideoTranscodingPayload = { | 14 | export type VideoTranscodingPayload = { |
@@ -19,28 +19,6 @@ export type VideoTranscodingPayload = { | |||
19 | generateHlsPlaylist?: boolean | 19 | generateHlsPlaylist?: boolean |
20 | } | 20 | } |
21 | 21 | ||
22 | export type VideoFileImportPayload = { | ||
23 | videoUUID: string, | ||
24 | filePath: string | ||
25 | } | ||
26 | |||
27 | async function processVideoFileImport (job: Bull.Job) { | ||
28 | const payload = job.data as VideoFileImportPayload | ||
29 | logger.info('Processing video file import in job %d.', job.id) | ||
30 | |||
31 | const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(payload.videoUUID) | ||
32 | // No video, maybe deleted? | ||
33 | if (!video) { | ||
34 | logger.info('Do not process job %d, video does not exist.', job.id) | ||
35 | return undefined | ||
36 | } | ||
37 | |||
38 | await importVideoFile(video, payload.filePath) | ||
39 | |||
40 | await onVideoFileTranscoderOrImportSuccess(video) | ||
41 | return video | ||
42 | } | ||
43 | |||
44 | async function processVideoTranscoding (job: Bull.Job) { | 22 | async function processVideoTranscoding (job: Bull.Job) { |
45 | const payload = job.data as VideoTranscodingPayload | 23 | const payload = job.data as VideoTranscodingPayload |
46 | logger.info('Processing video file in job %d.', job.id) | 24 | logger.info('Processing video file in job %d.', job.id) |
@@ -59,7 +37,7 @@ async function processVideoTranscoding (job: Bull.Job) { | |||
59 | } else if (payload.resolution) { // Transcoding in other resolution | 37 | } else if (payload.resolution) { // Transcoding in other resolution |
60 | await transcodeOriginalVideofile(video, payload.resolution, payload.isPortraitMode || false) | 38 | await transcodeOriginalVideofile(video, payload.resolution, payload.isPortraitMode || false) |
61 | 39 | ||
62 | await retryTransactionWrapper(onVideoFileTranscoderOrImportSuccess, video, payload) | 40 | await retryTransactionWrapper(publishVideoIfNeeded, video, payload) |
63 | } else { | 41 | } else { |
64 | await optimizeVideofile(video) | 42 | await optimizeVideofile(video) |
65 | 43 | ||
@@ -83,9 +61,7 @@ async function onHlsPlaylistGenerationSuccess (video: VideoModel) { | |||
83 | }) | 61 | }) |
84 | } | 62 | } |
85 | 63 | ||
86 | async function onVideoFileTranscoderOrImportSuccess (video: VideoModel, payload?: VideoTranscodingPayload) { | 64 | async function publishVideoIfNeeded (video: VideoModel, payload?: VideoTranscodingPayload) { |
87 | if (video === undefined) return undefined | ||
88 | |||
89 | const { videoDatabase, videoPublished } = await sequelizeTypescript.transaction(async t => { | 65 | const { videoDatabase, videoPublished } = await sequelizeTypescript.transaction(async t => { |
90 | // Maybe the video changed in database, refresh it | 66 | // Maybe the video changed in database, refresh it |
91 | let videoDatabase = await VideoModel.loadAndPopulateAccountAndServerAndTags(video.uuid, t) | 67 | let videoDatabase = await VideoModel.loadAndPopulateAccountAndServerAndTags(video.uuid, t) |
@@ -183,7 +159,7 @@ async function onVideoFileOptimizerSuccess (videoArg: VideoModel, payload: Video | |||
183 | 159 | ||
184 | export { | 160 | export { |
185 | processVideoTranscoding, | 161 | processVideoTranscoding, |
186 | processVideoFileImport | 162 | publishVideoIfNeeded |
187 | } | 163 | } |
188 | 164 | ||
189 | // --------------------------------------------------------------------------- | 165 | // --------------------------------------------------------------------------- |