]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/jobs/transcoding-job-scheduler/video-file-transcoder-handler.ts
Make it compile at least
[github/Chocobozzz/PeerTube.git] / server / lib / jobs / transcoding-job-scheduler / video-file-transcoder-handler.ts
CommitLineData
571389d4 1import { VideoResolution } from '../../../../shared'
65fcc311 2import { logger } from '../../../helpers'
571389d4 3import { database as db } from '../../../initializers/database'
69818c93 4import { VideoInstance } from '../../../models'
571389d4 5import { sendUpdateVideo } from '../../activitypub/send-request'
227d02fe 6
f5028693 7async function process (data: { videoUUID: string, resolution: VideoResolution }, jobId: number) {
38fa2065 8 const video = await db.Video.loadByUUIDAndPopulateAccountAndPodAndTags(data.videoUUID)
f5028693
C
9 // No video, maybe deleted?
10 if (!video) {
11 logger.info('Do not process job %d, video does not exist.', jobId, { videoUUID: video.uuid })
12 return undefined
13 }
14
15 await video.transcodeOriginalVideofile(data.resolution)
16
17 return video
227d02fe
C
18}
19
6fcd19ba 20function onError (err: Error, jobId: number) {
ad0997ad 21 logger.error('Error when transcoding video file in job %d.', jobId, err)
6fcd19ba 22 return Promise.resolve()
227d02fe
C
23}
24
4077df72 25async function onSuccess (jobId: number, video: VideoInstance) {
031094f7
C
26 if (video === undefined) return undefined
27
227d02fe 28 logger.info('Job %d is a success.', jobId)
62326afb 29
4077df72 30 // Maybe the video changed in database, refresh it
38fa2065 31 const videoDatabase = await db.Video.loadByUUIDAndPopulateAccountAndPodAndTags(video.uuid)
4077df72
C
32 // Video does not exist anymore
33 if (!videoDatabase) return undefined
34
571389d4 35 await sendUpdateVideo(video, undefined)
4077df72 36
7ff7802a 37 return undefined
227d02fe
C
38}
39
40// ---------------------------------------------------------------------------
41
65fcc311
C
42export {
43 process,
44 onError,
45 onSuccess
46}