From 4077df72c634ff17aaf69cc612fc6bb8d68b1ed8 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 26 Oct 2017 14:22:37 +0200 Subject: Fix integrity with transcoding jobs --- server/lib/jobs/handlers/video-file-optimizer.ts | 15 ++++++++++----- server/lib/jobs/handlers/video-file-transcoder.ts | 13 ++++++++++--- 2 files changed, 20 insertions(+), 8 deletions(-) (limited to 'server/lib/jobs') diff --git a/server/lib/jobs/handlers/video-file-optimizer.ts b/server/lib/jobs/handlers/video-file-optimizer.ts index 799ba8b01..ccded4721 100644 --- a/server/lib/jobs/handlers/video-file-optimizer.ts +++ b/server/lib/jobs/handlers/video-file-optimizer.ts @@ -29,17 +29,22 @@ async function onSuccess (jobId: number, video: VideoInstance) { logger.info('Job %d is a success.', jobId) - const remoteVideo = await video.toAddRemoteJSON() + // Maybe the video changed in database, refresh it + const videoDatabase = await db.Video.loadByUUIDAndPopulateAuthorAndPodAndTags(video.uuid) + // Video does not exist anymore + if (!videoDatabase) return undefined + + const remoteVideo = await videoDatabase.toAddRemoteJSON() // Now we'll add the video's meta data to our friends await addVideoToFriends(remoteVideo, null) - const originalFileHeight = await video.getOriginalFileHeight() + const originalFileHeight = await videoDatabase.getOriginalFileHeight() // Create transcoding jobs if there are enabled resolutions const resolutionsEnabled = computeResolutionsToTranscode(originalFileHeight) logger.info( - 'Resolutions computed for video %s and origin file height of %d.', video.uuid, originalFileHeight, + 'Resolutions computed for video %s and origin file height of %d.', videoDatabase.uuid, originalFileHeight, { resolutions: resolutionsEnabled } ) @@ -50,7 +55,7 @@ async function onSuccess (jobId: number, video: VideoInstance) { for (const resolution of resolutionsEnabled) { const dataInput = { - videoUUID: video.uuid, + videoUUID: videoDatabase.uuid, resolution } @@ -61,7 +66,7 @@ async function onSuccess (jobId: number, video: VideoInstance) { await Promise.all(tasks) }) - logger.info('Transcoding jobs created for uuid %s.', video.uuid, { resolutionsEnabled }) + logger.info('Transcoding jobs created for uuid %s.', videoDatabase.uuid, { resolutionsEnabled }) } catch (err) { logger.warn('Cannot transcode the video.', err) } diff --git a/server/lib/jobs/handlers/video-file-transcoder.ts b/server/lib/jobs/handlers/video-file-transcoder.ts index b240ff58a..a8d80ed45 100644 --- a/server/lib/jobs/handlers/video-file-transcoder.ts +++ b/server/lib/jobs/handlers/video-file-transcoder.ts @@ -22,15 +22,22 @@ function onError (err: Error, jobId: number) { return Promise.resolve() } -function onSuccess (jobId: number, video: VideoInstance) { +async function onSuccess (jobId: number, video: VideoInstance) { if (video === undefined) return undefined logger.info('Job %d is a success.', jobId) - const remoteVideo = video.toUpdateRemoteJSON() + // Maybe the video changed in database, refresh it + const videoDatabase = await db.Video.loadByUUIDAndPopulateAuthorAndPodAndTags(video.uuid) + // Video does not exist anymore + if (!videoDatabase) return undefined + + const remoteVideo = videoDatabase.toUpdateRemoteJSON() // Now we'll add the video's meta data to our friends - return updateVideoToFriends(remoteVideo, null) + await updateVideoToFriends(remoteVideo, null) + + return } // --------------------------------------------------------------------------- -- cgit v1.2.3