X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;ds=sidebyside;f=server%2Flib%2Fvideo-state.ts;h=b5d8353b77c641f4bb7ed888ab4d4661f1f75102;hb=ce6b3765a2d31b9b90b7a1435e7180b91cba57b3;hp=7b207eb8754b61a7e065d8eaf34fd798001955d1;hpb=92e66e04f7f51d37b465cff442ce47f6d6d7cadd;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/video-state.ts b/server/lib/video-state.ts index 7b207eb87..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.loadAndPopulateAccountAndServerAndTags(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 }) + } + }) }) } @@ -126,12 +129,10 @@ async function moveToPublishedState (options: { const { video, isNewVideo, transaction, previousVideoState } = options const previousState = previousVideoState ?? video.state - logger.info('Publishing video %s.', video.uuid, { previousState, tags: [ video.uuid ] }) + logger.info('Publishing video %s.', video.uuid, { isNewVideo, previousState, tags: [ video.uuid ] }) await video.setNewState(VideoState.PUBLISHED, isNewVideo, transaction) - // If the video was not published, we consider it is a new one for other instances - // Live videos are always federated, so it's not a new video await federateVideoIfNeeded(video, isNewVideo, transaction) if (previousState === VideoState.TO_EDIT) {