]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/jobs/transcoding-job-scheduler/video-file-transcoder-handler.ts
Status are sent to mastodon
[github/Chocobozzz/PeerTube.git] / server / lib / jobs / transcoding-job-scheduler / video-file-transcoder-handler.ts
CommitLineData
571389d4 1import { VideoResolution } from '../../../../shared'
e12a0092 2import { VideoPrivacy } from '../../../../shared/models/videos'
65fcc311 3import { logger } from '../../../helpers'
3fd3ab2d
C
4import { VideoModel } from '../../../models/video/video'
5import { sendUpdateVideo } from '../../activitypub/send'
227d02fe 6
f5028693 7async function process (data: { videoUUID: string, resolution: VideoResolution }, jobId: number) {
3fd3ab2d 8 const video = await VideoModel.loadByUUIDAndPopulateAccountAndServerAndTags(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
3fd3ab2d 25async function onSuccess (jobId: number, video: VideoModel) {
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
3fd3ab2d 31 const videoDatabase = await VideoModel.loadByUUIDAndPopulateAccountAndServerAndTags(video.uuid)
4077df72
C
32 // Video does not exist anymore
33 if (!videoDatabase) return undefined
34
e12a0092
C
35 if (video.privacy !== VideoPrivacy.PRIVATE) {
36 await sendUpdateVideo(video, undefined)
37 }
4077df72 38
7ff7802a 39 return undefined
227d02fe
C
40}
41
42// ---------------------------------------------------------------------------
43
65fcc311
C
44export {
45 process,
46 onError,
47 onSuccess
48}