]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/lib/jobs/handlers/video-transcoder.js
Server: add job scheduler to transcode video files
[github/Chocobozzz/PeerTube.git] / server / lib / jobs / handlers / video-transcoder.js
1 'use strict'
2
3 const db = require('../../../initializers/database')
4 const logger = require('../../../helpers/logger')
5
6 const VideoTranscoderHandler = {
7 process,
8 onError,
9 onSuccess
10 }
11
12 // ---------------------------------------------------------------------------
13
14 function process (data, callback) {
15 db.Video.load(data.id, function (err, video) {
16 if (err) return callback(err)
17
18 video.transcodeVideofile(callback)
19 })
20 }
21
22 function onError (err, jobId, callback) {
23 logger.error('Error when transcoding video file in job %d.', jobId, { error: err })
24 return callback()
25 }
26
27 function onSuccess (data, jobId, callback) {
28 logger.info('Job %d is a success.', jobId)
29 return callback()
30 }
31
32 // ---------------------------------------------------------------------------
33
34 module.exports = VideoTranscoderHandler