aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/jobs/handlers/video-transcoder.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-07-05 13:26:25 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-07-05 14:14:16 +0200
commit6fcd19ba737f1f5614a56c6925adb882dea43b8d (patch)
tree3365a96d82bc7f00ae504a568725c8e914150cf8 /server/lib/jobs/handlers/video-transcoder.ts
parent5fe7e898316e18369c3e1aba307b55077adc7bfb (diff)
downloadPeerTube-6fcd19ba737f1f5614a56c6925adb882dea43b8d.tar.gz
PeerTube-6fcd19ba737f1f5614a56c6925adb882dea43b8d.tar.zst
PeerTube-6fcd19ba737f1f5614a56c6925adb882dea43b8d.zip
Move to promises
Closes https://github.com/Chocobozzz/PeerTube/issues/74
Diffstat (limited to 'server/lib/jobs/handlers/video-transcoder.ts')
-rw-r--r--server/lib/jobs/handlers/video-transcoder.ts22
1 files changed, 8 insertions, 14 deletions
diff --git a/server/lib/jobs/handlers/video-transcoder.ts b/server/lib/jobs/handlers/video-transcoder.ts
index 6f606a7d3..e829ca813 100644
--- a/server/lib/jobs/handlers/video-transcoder.ts
+++ b/server/lib/jobs/handlers/video-transcoder.ts
@@ -3,29 +3,23 @@ import { logger } from '../../../helpers'
3import { addVideoToFriends } from '../../../lib' 3import { addVideoToFriends } from '../../../lib'
4import { VideoInstance } from '../../../models' 4import { VideoInstance } from '../../../models'
5 5
6function process (data: { id: string }, callback: (err: Error, videoInstance?: VideoInstance) => void) { 6function process (data: { id: string }) {
7 db.Video.loadAndPopulateAuthorAndPodAndTags(data.id, function (err, video) { 7 return db.Video.loadAndPopulateAuthorAndPodAndTags(data.id).then(video => {
8 if (err) return callback(err) 8 return video.transcodeVideofile().then(() => video)
9
10 video.transcodeVideofile(function (err) {
11 return callback(err, video)
12 })
13 }) 9 })
14} 10}
15 11
16function onError (err: Error, jobId: number, video: VideoInstance, callback: (err: Error) => void) { 12function onError (err: Error, jobId: number) {
17 logger.error('Error when transcoding video file in job %d.', jobId, { error: err }) 13 logger.error('Error when transcoding video file in job %d.', jobId, { error: err })
18 return callback(null) 14 return Promise.resolve()
19} 15}
20 16
21function onSuccess (data: any, jobId: number, video: VideoInstance, callback: (err: Error) => void) { 17function onSuccess (jobId: number, video: VideoInstance) {
22 logger.info('Job %d is a success.', jobId) 18 logger.info('Job %d is a success.', jobId)
23 19
24 video.toAddRemoteJSON(function (err, remoteVideo) { 20 video.toAddRemoteJSON().then(remoteVideo => {
25 if (err) return callback(err)
26
27 // Now we'll add the video's meta data to our friends 21 // Now we'll add the video's meta data to our friends
28 addVideoToFriends(remoteVideo, null, callback) 22 return addVideoToFriends(remoteVideo, null)
29 }) 23 })
30} 24}
31 25