1 import { VideoResolution } from '../../../../shared'
2 import { logger } from '../../../helpers'
3 import { VideoModel } from '../../../models/video/video'
4 import { sendUpdateVideo } from '../../activitypub/send'
6 async function process (data: { videoUUID: string, resolution: VideoResolution }, jobId: number) {
7 const video = await VideoModel.loadByUUIDAndPopulateAccountAndServerAndTags(data.videoUUID)
8 // No video, maybe deleted?
10 logger.info('Do not process job %d, video does not exist.', jobId, { videoUUID: video.uuid })
14 await video.transcodeOriginalVideofile(data.resolution)
19 function onError (err: Error, jobId: number) {
20 logger.error('Error when transcoding video file in job %d.', jobId, err)
21 return Promise.resolve()
24 async function onSuccess (jobId: number, video: VideoModel) {
25 if (video === undefined) return undefined
27 logger.info('Job %d is a success.', jobId)
29 // Maybe the video changed in database, refresh it
30 const videoDatabase = await VideoModel.loadByUUIDAndPopulateAccountAndServerAndTags(video.uuid)
31 // Video does not exist anymore
32 if (!videoDatabase) return undefined
34 await sendUpdateVideo(video, undefined)
39 // ---------------------------------------------------------------------------