aboutsummaryrefslogblamecommitdiffhomepage
path: root/server/lib/jobs/transcoding-job-scheduler/video-file-transcoder-handler.ts
blob: 77e5d9f7f744cb73d13fa052d64dc79d649a0be5 (plain) (tree)
1
2
3
4
5
6
7
8
                                                    
                                         
                                                               
                                               
                                                                
 
                                                                                                  
                                                                                        








                                                                                                 

 
                                              
                                                                          
                          

 
                                                                

                                           
                                            
 
                                                    
                                                                                            


                                      
                                         
 
                  



                                                                              




           
import { VideoResolution } from '../../../../shared'
import { logger } from '../../../helpers'
import { database as db } from '../../../initializers/database'
import { VideoInstance } from '../../../models'
import { sendUpdateVideo } from '../../activitypub/send-request'

async function process (data: { videoUUID: string, resolution: VideoResolution }, jobId: number) {
  const video = await db.Video.loadByUUIDAndPopulateAccountAndPodAndTags(data.videoUUID)
  // No video, maybe deleted?
  if (!video) {
    logger.info('Do not process job %d, video does not exist.', jobId, { videoUUID: video.uuid })
    return undefined
  }

  await video.transcodeOriginalVideofile(data.resolution)

  return video
}

function onError (err: Error, jobId: number) {
  logger.error('Error when transcoding video file in job %d.', jobId, err)
  return Promise.resolve()
}

async function onSuccess (jobId: number, video: VideoInstance) {
  if (video === undefined) return undefined

  logger.info('Job %d is a success.', jobId)

  // Maybe the video changed in database, refresh it
  const videoDatabase = await db.Video.loadByUUIDAndPopulateAccountAndPodAndTags(video.uuid)
  // Video does not exist anymore
  if (!videoDatabase) return undefined

  await sendUpdateVideo(video, undefined)

  return undefined
}

// ---------------------------------------------------------------------------

export {
  process,
  onError,
  onSuccess
}