diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-05-02 22:02:27 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-05-04 21:12:32 +0200 |
commit | 227d02feadbc9b1fc916a12528ccc0623fb3069e (patch) | |
tree | 0b6bcc8c2c081591588714bc040ac6e810e333de /server/lib/jobs/handlers/video-transcoder.js | |
parent | 15d4ee04a94230e1ea83c2959a1981105699ba22 (diff) | |
download | PeerTube-227d02feadbc9b1fc916a12528ccc0623fb3069e.tar.gz PeerTube-227d02feadbc9b1fc916a12528ccc0623fb3069e.tar.zst PeerTube-227d02feadbc9b1fc916a12528ccc0623fb3069e.zip |
Server: add job scheduler to transcode video files
Diffstat (limited to 'server/lib/jobs/handlers/video-transcoder.js')
-rw-r--r-- | server/lib/jobs/handlers/video-transcoder.js | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/server/lib/jobs/handlers/video-transcoder.js b/server/lib/jobs/handlers/video-transcoder.js new file mode 100644 index 000000000..8524df3aa --- /dev/null +++ b/server/lib/jobs/handlers/video-transcoder.js | |||
@@ -0,0 +1,34 @@ | |||
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 | ||