From 4e29f4fe23b413cc8c55ac0d8373f36bcd60b47a Mon Sep 17 00:00:00 2001 From: kontrollanten <6680299+kontrollanten@users.noreply.github.com> Date: Mon, 8 Nov 2021 04:20:04 +0100 Subject: video: add video stranscoding_failed state --- server/initializers/constants.ts | 3 ++- server/lib/job-queue/handlers/video-transcoding.ts | 11 +++++++++-- server/lib/video-state.ts | 7 +++++++ shared/models/videos/video-state.enum.ts | 3 ++- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index fb6bc9a66..845576667 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts @@ -420,7 +420,8 @@ const VIDEO_STATES: { [ id in VideoState ]: string } = { [VideoState.TO_IMPORT]: 'To import', [VideoState.WAITING_FOR_LIVE]: 'Waiting for livestream', [VideoState.LIVE_ENDED]: 'Livestream ended', - [VideoState.TO_MOVE_TO_EXTERNAL_STORAGE]: 'To move to an external storage' + [VideoState.TO_MOVE_TO_EXTERNAL_STORAGE]: 'To move to an external storage', + [VideoState.TRANSCODING_FAILED]: 'Transcoding failed' } const VIDEO_IMPORT_STATES: { [ id in VideoImportState ]: string } = { diff --git a/server/lib/job-queue/handlers/video-transcoding.ts b/server/lib/job-queue/handlers/video-transcoding.ts index 20880cdc1..b280a1cc9 100644 --- a/server/lib/job-queue/handlers/video-transcoding.ts +++ b/server/lib/job-queue/handlers/video-transcoding.ts @@ -2,7 +2,7 @@ import { Job } from 'bull' import { TranscodeOptionsType } from '@server/helpers/ffmpeg-utils' import { addTranscodingJob, getTranscodingJobPriority } from '@server/lib/video' import { VideoPathManager } from '@server/lib/video-path-manager' -import { moveToNextState } from '@server/lib/video-state' +import { moveToFailedState, moveToNextState } from '@server/lib/video-state' import { UserModel } from '@server/models/user/user' import { VideoJobInfoModel } from '@server/models/video/video-job-info' import { MUser, MUserId, MVideo, MVideoFullLight, MVideoWithFile } from '@server/types/models' @@ -52,10 +52,17 @@ async function processVideoTranscoding (job: Job) { const handler = handlers[payload.type] if (!handler) { + await moveToFailedState(video) throw new Error('Cannot find transcoding handler for ' + payload.type) } - await handler(job, payload, video, user) + try { + await handler(job, payload, video, user) + } catch (error) { + await moveToFailedState(video) + + throw error + } return video } diff --git a/server/lib/video-state.ts b/server/lib/video-state.ts index d5bbbec43..2260e90f5 100644 --- a/server/lib/video-state.ts +++ b/server/lib/video-state.ts @@ -79,11 +79,18 @@ async function moveToExternalStorageState (video: MVideoFullLight, isNewVideo: b } } +function moveToFailedState (video: MVideoFullLight) { + return sequelizeTypescript.transaction(async t => { + await video.setNewState(VideoState.TRANSCODING_FAILED, false, t) + }) +} + // --------------------------------------------------------------------------- export { buildNextVideoState, moveToExternalStorageState, + moveToFailedState, moveToNextState } diff --git a/shared/models/videos/video-state.enum.ts b/shared/models/videos/video-state.enum.ts index c6af481e7..6112b6e16 100644 --- a/shared/models/videos/video-state.enum.ts +++ b/shared/models/videos/video-state.enum.ts @@ -4,5 +4,6 @@ export const enum VideoState { TO_IMPORT = 3, WAITING_FOR_LIVE = 4, LIVE_ENDED = 5, - TO_MOVE_TO_EXTERNAL_STORAGE = 6 + TO_MOVE_TO_EXTERNAL_STORAGE = 6, + TRANSCODING_FAILED = 7 } -- cgit v1.2.3