2 import { retryTransactionWrapper } from '@server/helpers/database-utils'
3 import { logger } from '@server/helpers/logger'
4 import { moveToFailedTranscodingState, moveToNextState } from '@server/lib/video-state'
5 import { VideoJobInfoModel } from '@server/models/video/video-job-info'
6 import { MRunnerJob } from '@server/types/models/runners'
7 import { RunnerJobSuccessPayload, RunnerJobUpdatePayload, RunnerJobVODPrivatePayload } from '@shared/models'
8 import { AbstractJobHandler } from './abstract-job-handler'
9 import { loadTranscodingRunnerVideo } from './shared'
11 // eslint-disable-next-line max-len
12 export abstract class AbstractVODTranscodingJobHandler <C, U extends RunnerJobUpdatePayload, S extends RunnerJobSuccessPayload> extends AbstractJobHandler<C, U, S> {
14 protected isAbortSupported () {
18 protected specificUpdate (_options: {
24 protected specificAbort (_options: {
30 protected async specificError (options: {
33 const video = await loadTranscodingRunnerVideo(options.runnerJob, this.lTags)
36 await moveToFailedTranscodingState(video)
38 await VideoJobInfoModel.decrease(video.uuid, 'pendingTranscode')
41 protected async specificCancel (options: {
44 const { runnerJob } = options
46 const video = await loadTranscodingRunnerVideo(options.runnerJob, this.lTags)
49 const pending = await VideoJobInfoModel.decrease(video.uuid, 'pendingTranscode')
51 logger.debug(`Pending transcode decreased to ${pending} after cancel`, this.lTags(video.uuid))
55 `All transcoding jobs of ${video.uuid} have been processed or canceled, moving it to its next state`,
56 this.lTags(video.uuid)
59 const privatePayload = runnerJob.privatePayload as RunnerJobVODPrivatePayload
60 await retryTransactionWrapper(moveToNextState, { video, isNewVideo: privatePayload.isNewVideo })