From 031094f7992366d8d1f6583b205f984ffadf637a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 17 Oct 2017 15:37:40 +0200 Subject: More robust transcoding jobs --- server/lib/jobs/handlers/index.ts | 2 +- server/lib/jobs/handlers/video-file-optimizer.ts | 10 +++++++++- server/lib/jobs/handlers/video-file-transcoder.ts | 10 +++++++++- server/lib/jobs/job-scheduler.ts | 2 +- 4 files changed, 20 insertions(+), 4 deletions(-) (limited to 'server/lib/jobs') 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' import * as videoFileTranscoder from './video-file-transcoder' export interface JobHandler { - process (data: object): T + process (data: object, jobId: number): T onError (err: Error, jobId: number) onSuccess (jobId: number, jobResult: T) } 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' import { addVideoToFriends } from '../../friends' import { JobScheduler } from '../job-scheduler' -function process (data: { videoUUID: string }) { +function process (data: { videoUUID: string }, jobId: number) { return db.Video.loadByUUIDAndPopulateAuthorAndPodAndTags(data.videoUUID).then(video => { + // No video, maybe deleted? + if (!video) { + logger.info('Do not process job %d, video does not exist.', jobId, { videoUUID: video.uuid }) + return undefined + } + return video.optimizeOriginalVideofile().then(() => video) }) } @@ -18,6 +24,8 @@ function onError (err: Error, jobId: number) { } function onSuccess (jobId: number, video: VideoInstance) { + if (video === undefined) return undefined + logger.info('Job %d is a success.', jobId) 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' import { VideoInstance } from '../../../models' import { VideoResolution } from '../../../../shared' -function process (data: { videoUUID: string, resolution: VideoResolution }) { +function process (data: { videoUUID: string, resolution: VideoResolution }, jobId: number) { return db.Video.loadByUUIDAndPopulateAuthorAndPodAndTags(data.videoUUID).then(video => { + // No video, maybe deleted? + if (!video) { + logger.info('Do not process job %d, video does not exist.', jobId, { videoUUID: video.uuid }) + return undefined + } + return video.transcodeOriginalVideofile(data.resolution).then(() => video) }) } @@ -16,6 +22,8 @@ function onError (err: Error, jobId: number) { } function onSuccess (jobId: number, video: VideoInstance) { + if (video === undefined) return undefined + logger.info('Job %d is a success.', jobId) 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 { job.state = JOB_STATES.PROCESSING return job.save() .then(() => { - return jobHandler.process(job.handlerInputData) + return jobHandler.process(job.handlerInputData, job.id) }) .then( result => { -- cgit v1.2.3