aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/jobs/handlers
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-10-26 14:22:37 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-10-26 14:22:37 +0200
commit4077df72c634ff17aaf69cc612fc6bb8d68b1ed8 (patch)
tree03fdc7d773c447cd883f8b277945e5610bf70a34 /server/lib/jobs/handlers
parent911238e343e1cccae349ff9c44bcffadb96fa393 (diff)
downloadPeerTube-4077df72c634ff17aaf69cc612fc6bb8d68b1ed8.tar.gz
PeerTube-4077df72c634ff17aaf69cc612fc6bb8d68b1ed8.tar.zst
PeerTube-4077df72c634ff17aaf69cc612fc6bb8d68b1ed8.zip
Fix integrity with transcoding jobs
Diffstat (limited to 'server/lib/jobs/handlers')
-rw-r--r--server/lib/jobs/handlers/video-file-optimizer.ts15
-rw-r--r--server/lib/jobs/handlers/video-file-transcoder.ts13
2 files changed, 20 insertions, 8 deletions
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) {
29 29
30 logger.info('Job %d is a success.', jobId) 30 logger.info('Job %d is a success.', jobId)
31 31
32 const remoteVideo = await video.toAddRemoteJSON() 32 // Maybe the video changed in database, refresh it
33 const videoDatabase = await db.Video.loadByUUIDAndPopulateAuthorAndPodAndTags(video.uuid)
34 // Video does not exist anymore
35 if (!videoDatabase) return undefined
36
37 const remoteVideo = await videoDatabase.toAddRemoteJSON()
33 38
34 // Now we'll add the video's meta data to our friends 39 // Now we'll add the video's meta data to our friends
35 await addVideoToFriends(remoteVideo, null) 40 await addVideoToFriends(remoteVideo, null)
36 41
37 const originalFileHeight = await video.getOriginalFileHeight() 42 const originalFileHeight = await videoDatabase.getOriginalFileHeight()
38 // Create transcoding jobs if there are enabled resolutions 43 // Create transcoding jobs if there are enabled resolutions
39 44
40 const resolutionsEnabled = computeResolutionsToTranscode(originalFileHeight) 45 const resolutionsEnabled = computeResolutionsToTranscode(originalFileHeight)
41 logger.info( 46 logger.info(
42 'Resolutions computed for video %s and origin file height of %d.', video.uuid, originalFileHeight, 47 'Resolutions computed for video %s and origin file height of %d.', videoDatabase.uuid, originalFileHeight,
43 { resolutions: resolutionsEnabled } 48 { resolutions: resolutionsEnabled }
44 ) 49 )
45 50
@@ -50,7 +55,7 @@ async function onSuccess (jobId: number, video: VideoInstance) {
50 55
51 for (const resolution of resolutionsEnabled) { 56 for (const resolution of resolutionsEnabled) {
52 const dataInput = { 57 const dataInput = {
53 videoUUID: video.uuid, 58 videoUUID: videoDatabase.uuid,
54 resolution 59 resolution
55 } 60 }
56 61
@@ -61,7 +66,7 @@ async function onSuccess (jobId: number, video: VideoInstance) {
61 await Promise.all(tasks) 66 await Promise.all(tasks)
62 }) 67 })
63 68
64 logger.info('Transcoding jobs created for uuid %s.', video.uuid, { resolutionsEnabled }) 69 logger.info('Transcoding jobs created for uuid %s.', videoDatabase.uuid, { resolutionsEnabled })
65 } catch (err) { 70 } catch (err) {
66 logger.warn('Cannot transcode the video.', err) 71 logger.warn('Cannot transcode the video.', err)
67 } 72 }
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) {
22 return Promise.resolve() 22 return Promise.resolve()
23} 23}
24 24
25function onSuccess (jobId: number, video: VideoInstance) { 25async function onSuccess (jobId: number, video: VideoInstance) {
26 if (video === undefined) return undefined 26 if (video === undefined) return undefined
27 27
28 logger.info('Job %d is a success.', jobId) 28 logger.info('Job %d is a success.', jobId)
29 29
30 const remoteVideo = video.toUpdateRemoteJSON() 30 // Maybe the video changed in database, refresh it
31 const videoDatabase = await db.Video.loadByUUIDAndPopulateAuthorAndPodAndTags(video.uuid)
32 // Video does not exist anymore
33 if (!videoDatabase) return undefined
34
35 const remoteVideo = videoDatabase.toUpdateRemoteJSON()
31 36
32 // Now we'll add the video's meta data to our friends 37 // Now we'll add the video's meta data to our friends
33 return updateVideoToFriends(remoteVideo, null) 38 await updateVideoToFriends(remoteVideo, null)
39
40 return
34} 41}
35 42
36// --------------------------------------------------------------------------- 43// ---------------------------------------------------------------------------