diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-06-10 22:15:25 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-06-10 22:15:25 +0200 |
commit | 69818c9394366b954b6ba3bd697bd9d2b09f2a16 (patch) | |
tree | ad199a18ec3c322460d6f9523fc383ee562554e0 /server/lib/jobs/handlers | |
parent | 4d4e5cd4dca78480ec7f40e747f424cd107376a4 (diff) | |
download | PeerTube-69818c9394366b954b6ba3bd697bd9d2b09f2a16.tar.gz PeerTube-69818c9394366b954b6ba3bd697bd9d2b09f2a16.tar.zst PeerTube-69818c9394366b954b6ba3bd697bd9d2b09f2a16.zip |
Type functions
Diffstat (limited to 'server/lib/jobs/handlers')
-rw-r--r-- | server/lib/jobs/handlers/index.ts | 10 | ||||
-rw-r--r-- | server/lib/jobs/handlers/video-transcoder.ts | 7 |
2 files changed, 13 insertions, 4 deletions
diff --git a/server/lib/jobs/handlers/index.ts b/server/lib/jobs/handlers/index.ts index ae5440031..7d0263b15 100644 --- a/server/lib/jobs/handlers/index.ts +++ b/server/lib/jobs/handlers/index.ts | |||
@@ -1,6 +1,14 @@ | |||
1 | import * as videoTranscoder from './video-transcoder' | 1 | import * as videoTranscoder from './video-transcoder' |
2 | 2 | ||
3 | const jobHandlers = { | 3 | import { VideoInstance } from '../../../models' |
4 | |||
5 | export interface JobHandler<T> { | ||
6 | process (data: object, callback: (err: Error, videoInstance?: T) => void) | ||
7 | onError (err: Error, jobId: number, video: T, callback: (err: Error) => void) | ||
8 | onSuccess (data: any, jobId: number, video: T, callback: (err: Error) => void) | ||
9 | } | ||
10 | |||
11 | const jobHandlers: { [ handlerName: string ]: JobHandler<any> } = { | ||
4 | videoTranscoder | 12 | videoTranscoder |
5 | } | 13 | } |
6 | 14 | ||
diff --git a/server/lib/jobs/handlers/video-transcoder.ts b/server/lib/jobs/handlers/video-transcoder.ts index 43599356a..efa18ef2d 100644 --- a/server/lib/jobs/handlers/video-transcoder.ts +++ b/server/lib/jobs/handlers/video-transcoder.ts | |||
@@ -1,8 +1,9 @@ | |||
1 | import { database as db } from '../../../initializers/database' | 1 | import { database as db } from '../../../initializers/database' |
2 | import { logger } from '../../../helpers' | 2 | import { logger } from '../../../helpers' |
3 | import { addVideoToFriends } from '../../../lib' | 3 | import { addVideoToFriends } from '../../../lib' |
4 | import { VideoInstance } from '../../../models' | ||
4 | 5 | ||
5 | function process (data, callback) { | 6 | function process (data: { id: string }, callback: (err: Error, videoInstance?: VideoInstance) => void) { |
6 | db.Video.loadAndPopulateAuthorAndPodAndTags(data.id, function (err, video) { | 7 | db.Video.loadAndPopulateAuthorAndPodAndTags(data.id, function (err, video) { |
7 | if (err) return callback(err) | 8 | if (err) return callback(err) |
8 | 9 | ||
@@ -12,12 +13,12 @@ function process (data, callback) { | |||
12 | }) | 13 | }) |
13 | } | 14 | } |
14 | 15 | ||
15 | function onError (err, jobId, video, callback) { | 16 | function onError (err: Error, jobId: number, video: VideoInstance, callback: () => void) { |
16 | logger.error('Error when transcoding video file in job %d.', jobId, { error: err }) | 17 | logger.error('Error when transcoding video file in job %d.', jobId, { error: err }) |
17 | return callback() | 18 | return callback() |
18 | } | 19 | } |
19 | 20 | ||
20 | function onSuccess (data, jobId, video, callback) { | 21 | function onSuccess (data: any, jobId: number, video: VideoInstance, callback: (err: Error) => void) { |
21 | logger.info('Job %d is a success.', jobId) | 22 | logger.info('Job %d is a success.', jobId) |
22 | 23 | ||
23 | video.toAddRemoteJSON(function (err, remoteVideo) { | 24 | video.toAddRemoteJSON(function (err, remoteVideo) { |