1
0
Fork 0

More robust transcoding jobs

This commit is contained in:
Chocobozzz 2017-10-17 15:37:40 +02:00
parent a6218a0b8f
commit 031094f799
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
5 changed files with 23 additions and 7 deletions

View File

@ -2,7 +2,7 @@ import * as videoFileOptimizer from './video-file-optimizer'
import * as videoFileTranscoder from './video-file-transcoder'
export interface JobHandler<T> {
process (data: object): T
process (data: object, jobId: number): T
onError (err: Error, jobId: number)
onSuccess (jobId: number, jobResult: T)
}

View File

@ -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()

View File

@ -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()

View File

@ -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 => {

View File

@ -195,17 +195,17 @@ describe('Test multiple pods', function () {
const file240p = video.files.find(f => f.resolution === 240)
expect(file240p).not.to.be.undefined
expect(file240p.resolutionLabel).to.equal('240p')
expect(file240p.size).to.be.above(130000).and.below(150000)
expect(file240p.size).to.be.above(180000).and.below(200000)
const file360p = video.files.find(f => f.resolution === 360)
expect(file360p).not.to.be.undefined
expect(file360p.resolutionLabel).to.equal('360p')
expect(file360p.size).to.be.above(160000).and.below(180000)
expect(file360p.size).to.be.above(270000).and.below(290000)
const file480p = video.files.find(f => f.resolution === 480)
expect(file480p).not.to.be.undefined
expect(file480p.resolutionLabel).to.equal('480p')
expect(file480p.size).to.be.above(200000).and.below(220000)
expect(file480p.size).to.be.above(380000).and.below(400000)
const file720p = video.files.find(f => f.resolution === 720)
expect(file720p).not.to.be.undefined