]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/jobs/handlers/video-file-transcoder.ts
Use async/await in lib and initializers
[github/Chocobozzz/PeerTube.git] / server / lib / jobs / handlers / video-file-transcoder.ts
CommitLineData
e02643f3 1import { database as db } from '../../../initializers/database'
40298b02 2import { updateVideoToFriends } from '../../friends'
65fcc311 3import { logger } from '../../../helpers'
69818c93 4import { VideoInstance } from '../../../models'
40298b02 5import { VideoResolution } from '../../../../shared'
227d02fe 6
f5028693
C
7async function process (data: { videoUUID: string, resolution: VideoResolution }, jobId: number) {
8 const video = await db.Video.loadByUUIDAndPopulateAuthorAndPodAndTags(data.videoUUID)
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
6fcd19ba 25function 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
40298b02
C
30 const remoteVideo = video.toUpdateRemoteJSON()
31
32 // Now we'll add the video's meta data to our friends
33 return updateVideoToFriends(remoteVideo, null)
227d02fe
C
34}
35
36// ---------------------------------------------------------------------------
37
65fcc311
C
38export {
39 process,
40 onError,
41 onSuccess
42}