]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/job-queue/handlers/video-file.ts
Add timeout and TTL to request jobs
[github/Chocobozzz/PeerTube.git] / server / lib / job-queue / handlers / video-file.ts
index 5294483bda3fe1412fc4edbe35d960199063e3e9..1b41d29e862baa413ce17c6f8cc8415d129ce7ba 100644 (file)
@@ -11,7 +11,8 @@ import { JobQueue } from '../job-queue'
 
 export type VideoFilePayload = {
   videoUUID: string
-  resolution?: VideoResolution
+  resolution?: VideoResolution,
+  isPortraitMode?: boolean
 }
 
 async function processVideoFile (job: kue.Job) {
@@ -27,7 +28,7 @@ async function processVideoFile (job: kue.Job) {
 
   // Transcoding in other resolution
   if (payload.resolution) {
-    await video.transcodeOriginalVideofile(payload.resolution)
+    await video.transcodeOriginalVideofile(payload.resolution, payload.isPortraitMode)
     await onVideoFileTranscoderSuccess(video)
   } else {
     await video.optimizeOriginalVideofile()
@@ -62,41 +63,37 @@ async function onVideoFileOptimizerSuccess (video: VideoModel) {
 
   if (video.privacy !== VideoPrivacy.PRIVATE) {
     // Now we'll add the video's meta data to our followers
-    await sendCreateVideo(video, undefined)
-    await shareVideoByServerAndChannel(video, undefined)
+    await sequelizeTypescript.transaction(async t => {
+      await sendCreateVideo(video, t)
+      await shareVideoByServerAndChannel(video, t)
+    })
   }
 
-  const originalFileHeight = await videoDatabase.getOriginalFileHeight()
+  const { videoFileResolution } = await videoDatabase.getOriginalFileResolution()
 
   // Create transcoding jobs if there are enabled resolutions
-  const resolutionsEnabled = computeResolutionsToTranscode(originalFileHeight)
+  const resolutionsEnabled = computeResolutionsToTranscode(videoFileResolution)
   logger.info(
-    'Resolutions computed for video %s and origin file height of %d.', videoDatabase.uuid, originalFileHeight,
+    'Resolutions computed for video %s and origin file height of %d.', videoDatabase.uuid, videoFileResolution,
     { resolutions: resolutionsEnabled }
   )
 
   if (resolutionsEnabled.length !== 0) {
-    try {
-      await sequelizeTypescript.transaction(async t => {
-        const tasks: Promise<any>[] = []
-
-        for (const resolution of resolutionsEnabled) {
-          const dataInput = {
-            videoUUID: videoDatabase.uuid,
-            resolution
-          }
-
-          const p = JobQueue.Instance.createJob({ type: 'video-file', payload: dataInput })
-          tasks.push(p)
-        }
-
-        await Promise.all(tasks)
-      })
-
-      logger.info('Transcoding jobs created for uuid %s.', videoDatabase.uuid, { resolutionsEnabled })
-    } catch (err) {
-      logger.warn('Cannot transcode the video.', err)
+    const tasks: Promise<any>[] = []
+
+    for (const resolution of resolutionsEnabled) {
+      const dataInput = {
+        videoUUID: videoDatabase.uuid,
+        resolution
+      }
+
+      const p = JobQueue.Instance.createJob({ type: 'video-file', payload: dataInput })
+      tasks.push(p)
     }
+
+    await Promise.all(tasks)
+
+    logger.info('Transcoding jobs created for uuid %s.', videoDatabase.uuid, { resolutionsEnabled })
   } else {
     logger.info('No transcoding jobs created for video %s (no resolutions enabled).')
     return undefined