From 308421283adf8df1a6a1972cd0efe198b0d93435 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 19 Mar 2019 17:10:53 +0100 Subject: Move video file import in its own file --- server/lib/job-queue/handlers/video-transcoding.ts | 34 ++++------------------ 1 file changed, 5 insertions(+), 29 deletions(-) (limited to 'server/lib/job-queue/handlers/video-transcoding.ts') 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' import { JobQueue } from '../job-queue' import { federateVideoIfNeeded } from '../../activitypub' import { retryTransactionWrapper } from '../../../helpers/database-utils' -import { sequelizeTypescript, CONFIG } from '../../../initializers' +import { CONFIG, sequelizeTypescript } from '../../../initializers' import * as Bluebird from 'bluebird' import { computeResolutionsToTranscode } from '../../../helpers/ffmpeg-utils' -import { generateHlsPlaylist, importVideoFile, optimizeVideofile, transcodeOriginalVideofile } from '../../video-transcoding' +import { generateHlsPlaylist, optimizeVideofile, transcodeOriginalVideofile } from '../../video-transcoding' import { Notifier } from '../../notifier' export type VideoTranscodingPayload = { @@ -19,28 +19,6 @@ export type VideoTranscodingPayload = { generateHlsPlaylist?: boolean } -export type VideoFileImportPayload = { - videoUUID: string, - filePath: string -} - -async function processVideoFileImport (job: Bull.Job) { - const payload = job.data as VideoFileImportPayload - logger.info('Processing video file import in job %d.', job.id) - - const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(payload.videoUUID) - // No video, maybe deleted? - if (!video) { - logger.info('Do not process job %d, video does not exist.', job.id) - return undefined - } - - await importVideoFile(video, payload.filePath) - - await onVideoFileTranscoderOrImportSuccess(video) - return video -} - async function processVideoTranscoding (job: Bull.Job) { const payload = job.data as VideoTranscodingPayload logger.info('Processing video file in job %d.', job.id) @@ -59,7 +37,7 @@ async function processVideoTranscoding (job: Bull.Job) { } else if (payload.resolution) { // Transcoding in other resolution await transcodeOriginalVideofile(video, payload.resolution, payload.isPortraitMode || false) - await retryTransactionWrapper(onVideoFileTranscoderOrImportSuccess, video, payload) + await retryTransactionWrapper(publishVideoIfNeeded, video, payload) } else { await optimizeVideofile(video) @@ -83,9 +61,7 @@ async function onHlsPlaylistGenerationSuccess (video: VideoModel) { }) } -async function onVideoFileTranscoderOrImportSuccess (video: VideoModel, payload?: VideoTranscodingPayload) { - if (video === undefined) return undefined - +async function publishVideoIfNeeded (video: VideoModel, payload?: VideoTranscodingPayload) { const { videoDatabase, videoPublished } = await sequelizeTypescript.transaction(async t => { // Maybe the video changed in database, refresh it let videoDatabase = await VideoModel.loadAndPopulateAccountAndServerAndTags(video.uuid, t) @@ -183,7 +159,7 @@ async function onVideoFileOptimizerSuccess (videoArg: VideoModel, payload: Video export { processVideoTranscoding, - processVideoFileImport + publishVideoIfNeeded } // --------------------------------------------------------------------------- -- cgit v1.2.3