aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-10-17 15:37:40 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-10-17 15:37:40 +0200
commit031094f7992366d8d1f6583b205f984ffadf637a (patch)
tree34ee5dc91b3e540f6f0499beadbd74575d9ad434 /server/lib
parenta6218a0b8f685078e6f7d21e9110b6418c5594fe (diff)
downloadPeerTube-031094f7992366d8d1f6583b205f984ffadf637a.tar.gz
PeerTube-031094f7992366d8d1f6583b205f984ffadf637a.tar.zst
PeerTube-031094f7992366d8d1f6583b205f984ffadf637a.zip
More robust transcoding jobs
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/jobs/handlers/index.ts2
-rw-r--r--server/lib/jobs/handlers/video-file-optimizer.ts10
-rw-r--r--server/lib/jobs/handlers/video-file-transcoder.ts10
-rw-r--r--server/lib/jobs/job-scheduler.ts2
4 files changed, 20 insertions, 4 deletions
diff --git a/server/lib/jobs/handlers/index.ts b/server/lib/jobs/handlers/index.ts
index 5941427a1..cef1f89a9 100644
--- a/server/lib/jobs/handlers/index.ts
+++ b/server/lib/jobs/handlers/index.ts
@@ -2,7 +2,7 @@ import * as videoFileOptimizer from './video-file-optimizer'
2import * as videoFileTranscoder from './video-file-transcoder' 2import * as videoFileTranscoder from './video-file-transcoder'
3 3
4export interface JobHandler<T> { 4export interface JobHandler<T> {
5 process (data: object): T 5 process (data: object, jobId: number): T
6 onError (err: Error, jobId: number) 6 onError (err: Error, jobId: number)
7 onSuccess (jobId: number, jobResult: T) 7 onSuccess (jobId: number, jobResult: T)
8} 8}
diff --git a/server/lib/jobs/handlers/video-file-optimizer.ts b/server/lib/jobs/handlers/video-file-optimizer.ts
index a87ce52dc..63a51064c 100644
--- a/server/lib/jobs/handlers/video-file-optimizer.ts
+++ b/server/lib/jobs/handlers/video-file-optimizer.ts
@@ -6,8 +6,14 @@ import { VideoInstance } from '../../../models'
6import { addVideoToFriends } from '../../friends' 6import { addVideoToFriends } from '../../friends'
7import { JobScheduler } from '../job-scheduler' 7import { JobScheduler } from '../job-scheduler'
8 8
9function process (data: { videoUUID: string }) { 9function process (data: { videoUUID: string }, jobId: number) {
10 return db.Video.loadByUUIDAndPopulateAuthorAndPodAndTags(data.videoUUID).then(video => { 10 return db.Video.loadByUUIDAndPopulateAuthorAndPodAndTags(data.videoUUID).then(video => {
11 // No video, maybe deleted?
12 if (!video) {
13 logger.info('Do not process job %d, video does not exist.', jobId, { videoUUID: video.uuid })
14 return undefined
15 }
16
11 return video.optimizeOriginalVideofile().then(() => video) 17 return video.optimizeOriginalVideofile().then(() => video)
12 }) 18 })
13} 19}
@@ -18,6 +24,8 @@ function onError (err: Error, jobId: number) {
18} 24}
19 25
20function onSuccess (jobId: number, video: VideoInstance) { 26function onSuccess (jobId: number, video: VideoInstance) {
27 if (video === undefined) return undefined
28
21 logger.info('Job %d is a success.', jobId) 29 logger.info('Job %d is a success.', jobId)
22 30
23 video.toAddRemoteJSON() 31 video.toAddRemoteJSON()
diff --git a/server/lib/jobs/handlers/video-file-transcoder.ts b/server/lib/jobs/handlers/video-file-transcoder.ts
index 0e45b4dca..0dafee566 100644
--- a/server/lib/jobs/handlers/video-file-transcoder.ts
+++ b/server/lib/jobs/handlers/video-file-transcoder.ts
@@ -4,8 +4,14 @@ import { logger } from '../../../helpers'
4import { VideoInstance } from '../../../models' 4import { VideoInstance } from '../../../models'
5import { VideoResolution } from '../../../../shared' 5import { VideoResolution } from '../../../../shared'
6 6
7function process (data: { videoUUID: string, resolution: VideoResolution }) { 7function process (data: { videoUUID: string, resolution: VideoResolution }, jobId: number) {
8 return db.Video.loadByUUIDAndPopulateAuthorAndPodAndTags(data.videoUUID).then(video => { 8 return db.Video.loadByUUIDAndPopulateAuthorAndPodAndTags(data.videoUUID).then(video => {
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
9 return video.transcodeOriginalVideofile(data.resolution).then(() => video) 15 return video.transcodeOriginalVideofile(data.resolution).then(() => video)
10 }) 16 })
11} 17}
@@ -16,6 +22,8 @@ function onError (err: Error, jobId: number) {
16} 22}
17 23
18function onSuccess (jobId: number, video: VideoInstance) { 24function onSuccess (jobId: number, video: VideoInstance) {
25 if (video === undefined) return undefined
26
19 logger.info('Job %d is a success.', jobId) 27 logger.info('Job %d is a success.', jobId)
20 28
21 const remoteVideo = video.toUpdateRemoteJSON() 29 const remoteVideo = video.toUpdateRemoteJSON()
diff --git a/server/lib/jobs/job-scheduler.ts b/server/lib/jobs/job-scheduler.ts
index 134d270c0..c2409d20c 100644
--- a/server/lib/jobs/job-scheduler.ts
+++ b/server/lib/jobs/job-scheduler.ts
@@ -87,7 +87,7 @@ class JobScheduler {
87 job.state = JOB_STATES.PROCESSING 87 job.state = JOB_STATES.PROCESSING
88 return job.save() 88 return job.save()
89 .then(() => { 89 .then(() => {
90 return jobHandler.process(job.handlerInputData) 90 return jobHandler.process(job.handlerInputData, job.id)
91 }) 91 })
92 .then( 92 .then(
93 result => { 93 result => {