From 4ddb53f65d9d97fc3eb97d9dadcbbcf35d8ddab7 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 12 Jul 2022 16:25:21 +0200 Subject: Auto retry video state db query on failure --- server/lib/video-state.ts | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) (limited to 'server') diff --git a/server/lib/video-state.ts b/server/lib/video-state.ts index b4e3831e5..b5d8353b7 100644 --- a/server/lib/video-state.ts +++ b/server/lib/video-state.ts @@ -9,6 +9,7 @@ import { VideoState } from '@shared/models' import { federateVideoIfNeeded } from './activitypub/videos' import { Notifier } from './notifier' import { addMoveToObjectStorageJob } from './video' +import { retryTransactionWrapper } from '@server/helpers/database-utils' function buildNextVideoState (currentState?: VideoState) { if (currentState === VideoState.PUBLISHED) { @@ -41,26 +42,28 @@ function moveToNextState (options: { }) { const { video, previousVideoState, isNewVideo = true } = options - return sequelizeTypescript.transaction(async t => { - // Maybe the video changed in database, refresh it - const videoDatabase = await VideoModel.loadFull(video.uuid, t) - // Video does not exist anymore - if (!videoDatabase) return undefined + return retryTransactionWrapper(() => { + return sequelizeTypescript.transaction(async t => { + // Maybe the video changed in database, refresh it + const videoDatabase = await VideoModel.loadFull(video.uuid, t) + // Video does not exist anymore + if (!videoDatabase) return undefined - // Already in its final state - if (videoDatabase.state === VideoState.PUBLISHED) { - return federateVideoIfNeeded(videoDatabase, false, t) - } + // Already in its final state + if (videoDatabase.state === VideoState.PUBLISHED) { + return federateVideoIfNeeded(videoDatabase, false, t) + } - const newState = buildNextVideoState(videoDatabase.state) + const newState = buildNextVideoState(videoDatabase.state) - if (newState === VideoState.PUBLISHED) { - return moveToPublishedState({ video: videoDatabase, previousVideoState, isNewVideo, transaction: t }) - } + if (newState === VideoState.PUBLISHED) { + return moveToPublishedState({ video: videoDatabase, previousVideoState, isNewVideo, transaction: t }) + } - if (newState === VideoState.TO_MOVE_TO_EXTERNAL_STORAGE) { - return moveToExternalStorageState({ video: videoDatabase, isNewVideo, transaction: t }) - } + if (newState === VideoState.TO_MOVE_TO_EXTERNAL_STORAGE) { + return moveToExternalStorageState({ video: videoDatabase, isNewVideo, transaction: t }) + } + }) }) } -- cgit v1.2.3