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)
}
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)
})
}
}
function onSuccess (jobId: number, video: VideoInstance) {
+ if (video === undefined) return undefined
+
logger.info('Job %d is a success.', jobId)
video.toAddRemoteJSON()
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)
})
}
}
function onSuccess (jobId: number, video: VideoInstance) {
+ if (video === undefined) return undefined
+
logger.info('Job %d is a success.', jobId)
const remoteVideo = video.toUpdateRemoteJSON()
job.state = JOB_STATES.PROCESSING
return job.save()
.then(() => {
- return jobHandler.process(job.handlerInputData)
+ return jobHandler.process(job.handlerInputData, job.id)
})
.then(
result => {
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