Auto retry video state db query on failure
This commit is contained in:
parent
5220859984
commit
4ddb53f65d
|
@ -9,6 +9,7 @@ import { VideoState } from '@shared/models'
|
||||||
import { federateVideoIfNeeded } from './activitypub/videos'
|
import { federateVideoIfNeeded } from './activitypub/videos'
|
||||||
import { Notifier } from './notifier'
|
import { Notifier } from './notifier'
|
||||||
import { addMoveToObjectStorageJob } from './video'
|
import { addMoveToObjectStorageJob } from './video'
|
||||||
|
import { retryTransactionWrapper } from '@server/helpers/database-utils'
|
||||||
|
|
||||||
function buildNextVideoState (currentState?: VideoState) {
|
function buildNextVideoState (currentState?: VideoState) {
|
||||||
if (currentState === VideoState.PUBLISHED) {
|
if (currentState === VideoState.PUBLISHED) {
|
||||||
|
@ -41,26 +42,28 @@ function moveToNextState (options: {
|
||||||
}) {
|
}) {
|
||||||
const { video, previousVideoState, isNewVideo = true } = options
|
const { video, previousVideoState, isNewVideo = true } = options
|
||||||
|
|
||||||
return sequelizeTypescript.transaction(async t => {
|
return retryTransactionWrapper(() => {
|
||||||
// Maybe the video changed in database, refresh it
|
return sequelizeTypescript.transaction(async t => {
|
||||||
const videoDatabase = await VideoModel.loadFull(video.uuid, t)
|
// Maybe the video changed in database, refresh it
|
||||||
// Video does not exist anymore
|
const videoDatabase = await VideoModel.loadFull(video.uuid, t)
|
||||||
if (!videoDatabase) return undefined
|
// Video does not exist anymore
|
||||||
|
if (!videoDatabase) return undefined
|
||||||
|
|
||||||
// Already in its final state
|
// Already in its final state
|
||||||
if (videoDatabase.state === VideoState.PUBLISHED) {
|
if (videoDatabase.state === VideoState.PUBLISHED) {
|
||||||
return federateVideoIfNeeded(videoDatabase, false, t)
|
return federateVideoIfNeeded(videoDatabase, false, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
const newState = buildNextVideoState(videoDatabase.state)
|
const newState = buildNextVideoState(videoDatabase.state)
|
||||||
|
|
||||||
if (newState === VideoState.PUBLISHED) {
|
if (newState === VideoState.PUBLISHED) {
|
||||||
return moveToPublishedState({ video: videoDatabase, previousVideoState, isNewVideo, transaction: t })
|
return moveToPublishedState({ video: videoDatabase, previousVideoState, isNewVideo, transaction: t })
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newState === VideoState.TO_MOVE_TO_EXTERNAL_STORAGE) {
|
if (newState === VideoState.TO_MOVE_TO_EXTERNAL_STORAGE) {
|
||||||
return moveToExternalStorageState({ video: videoDatabase, isNewVideo, transaction: t })
|
return moveToExternalStorageState({ video: videoDatabase, isNewVideo, transaction: t })
|
||||||
}
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue