mirror of https://github.com/Chocobozzz/PeerTube
More robust transcoding jobs
parent
a6218a0b8f
commit
031094f799
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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 => {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue