PeerTube/server/lib/jobs/transcoding-job-scheduler/video-file-transcoder-handl...

49 lines
1.5 KiB
TypeScript
Raw Normal View History

2017-11-10 10:27:49 -06:00
import { VideoResolution } from '../../../../shared'
2017-12-19 03:34:56 -06:00
import { VideoPrivacy } from '../../../../shared/models/videos'
2017-12-28 04:16:08 -06:00
import { logger } from '../../../helpers/logger'
2017-12-12 10:53:50 -06:00
import { VideoModel } from '../../../models/video/video'
import { sendUpdateVideo } from '../../activitypub/send'
async function process (data: { videoUUID: string, resolution: VideoResolution }, jobId: number) {
2017-12-12 10:53:50 -06:00
const video = await VideoModel.loadByUUIDAndPopulateAccountAndServerAndTags(data.videoUUID)
// No video, maybe deleted?
if (!video) {
logger.info('Do not process job %d, video does not exist.', jobId, { videoUUID: video.uuid })
return undefined
}
await video.transcodeOriginalVideofile(data.resolution)
return video
}
function onError (err: Error, jobId: number) {
2017-07-07 11:26:12 -05:00
logger.error('Error when transcoding video file in job %d.', jobId, err)
return Promise.resolve()
}
2017-12-12 10:53:50 -06:00
async function onSuccess (jobId: number, video: VideoModel) {
2017-10-17 08:37:40 -05:00
if (video === undefined) return undefined
logger.info('Job %d is a success.', jobId)
2017-10-26 07:22:37 -05:00
// Maybe the video changed in database, refresh it
2017-12-12 10:53:50 -06:00
const videoDatabase = await VideoModel.loadByUUIDAndPopulateAccountAndServerAndTags(video.uuid)
2017-10-26 07:22:37 -05:00
// Video does not exist anymore
if (!videoDatabase) return undefined
2017-12-19 03:34:56 -06:00
if (video.privacy !== VideoPrivacy.PRIVATE) {
await sendUpdateVideo(video, undefined)
}
2017-10-26 07:22:37 -05:00
2017-10-26 08:16:05 -05:00
return undefined
}
// ---------------------------------------------------------------------------
2017-05-15 15:22:03 -05:00
export {
process,
onError,
onSuccess
}