diff options
-rw-r--r-- | server/lib/jobs/handlers/index.ts | 2 | ||||
-rw-r--r-- | server/lib/jobs/handlers/video-file-optimizer.ts | 10 | ||||
-rw-r--r-- | server/lib/jobs/handlers/video-file-transcoder.ts | 10 | ||||
-rw-r--r-- | server/lib/jobs/job-scheduler.ts | 2 | ||||
-rw-r--r-- | server/tests/api/multiple-pods.ts | 6 |
5 files changed, 23 insertions, 7 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' | |||
2 | import * as videoFileTranscoder from './video-file-transcoder' | 2 | import * as videoFileTranscoder from './video-file-transcoder' |
3 | 3 | ||
4 | export interface JobHandler<T> { | 4 | export 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' | |||
6 | import { addVideoToFriends } from '../../friends' | 6 | import { addVideoToFriends } from '../../friends' |
7 | import { JobScheduler } from '../job-scheduler' | 7 | import { JobScheduler } from '../job-scheduler' |
8 | 8 | ||
9 | function process (data: { videoUUID: string }) { | 9 | function 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 | ||
20 | function onSuccess (jobId: number, video: VideoInstance) { | 26 | function 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' | |||
4 | import { VideoInstance } from '../../../models' | 4 | import { VideoInstance } from '../../../models' |
5 | import { VideoResolution } from '../../../../shared' | 5 | import { VideoResolution } from '../../../../shared' |
6 | 6 | ||
7 | function process (data: { videoUUID: string, resolution: VideoResolution }) { | 7 | function 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 | ||
18 | function onSuccess (jobId: number, video: VideoInstance) { | 24 | function 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 => { |
diff --git a/server/tests/api/multiple-pods.ts b/server/tests/api/multiple-pods.ts index 8b60ac0f4..6c11aace5 100644 --- a/server/tests/api/multiple-pods.ts +++ b/server/tests/api/multiple-pods.ts | |||
@@ -195,17 +195,17 @@ describe('Test multiple pods', function () { | |||
195 | const file240p = video.files.find(f => f.resolution === 240) | 195 | const file240p = video.files.find(f => f.resolution === 240) |
196 | expect(file240p).not.to.be.undefined | 196 | expect(file240p).not.to.be.undefined |
197 | expect(file240p.resolutionLabel).to.equal('240p') | 197 | expect(file240p.resolutionLabel).to.equal('240p') |
198 | expect(file240p.size).to.be.above(130000).and.below(150000) | 198 | expect(file240p.size).to.be.above(180000).and.below(200000) |
199 | 199 | ||
200 | const file360p = video.files.find(f => f.resolution === 360) | 200 | const file360p = video.files.find(f => f.resolution === 360) |
201 | expect(file360p).not.to.be.undefined | 201 | expect(file360p).not.to.be.undefined |
202 | expect(file360p.resolutionLabel).to.equal('360p') | 202 | expect(file360p.resolutionLabel).to.equal('360p') |
203 | expect(file360p.size).to.be.above(160000).and.below(180000) | 203 | expect(file360p.size).to.be.above(270000).and.below(290000) |
204 | 204 | ||
205 | const file480p = video.files.find(f => f.resolution === 480) | 205 | const file480p = video.files.find(f => f.resolution === 480) |
206 | expect(file480p).not.to.be.undefined | 206 | expect(file480p).not.to.be.undefined |
207 | expect(file480p.resolutionLabel).to.equal('480p') | 207 | expect(file480p.resolutionLabel).to.equal('480p') |
208 | expect(file480p.size).to.be.above(200000).and.below(220000) | 208 | expect(file480p.size).to.be.above(380000).and.below(400000) |
209 | 209 | ||
210 | const file720p = video.files.find(f => f.resolution === 720) | 210 | const file720p = video.files.find(f => f.resolution === 720) |
211 | expect(file720p).not.to.be.undefined | 211 | expect(file720p).not.to.be.undefined |