diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/lib/video-state.ts | 35 |
1 files changed, 19 insertions, 16 deletions
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' | |||
9 | import { federateVideoIfNeeded } from './activitypub/videos' | 9 | import { federateVideoIfNeeded } from './activitypub/videos' |
10 | import { Notifier } from './notifier' | 10 | import { Notifier } from './notifier' |
11 | import { addMoveToObjectStorageJob } from './video' | 11 | import { addMoveToObjectStorageJob } from './video' |
12 | import { retryTransactionWrapper } from '@server/helpers/database-utils' | ||
12 | 13 | ||
13 | function buildNextVideoState (currentState?: VideoState) { | 14 | function buildNextVideoState (currentState?: VideoState) { |
14 | if (currentState === VideoState.PUBLISHED) { | 15 | if (currentState === VideoState.PUBLISHED) { |
@@ -41,26 +42,28 @@ function moveToNextState (options: { | |||
41 | }) { | 42 | }) { |
42 | const { video, previousVideoState, isNewVideo = true } = options | 43 | const { video, previousVideoState, isNewVideo = true } = options |
43 | 44 | ||
44 | return sequelizeTypescript.transaction(async t => { | 45 | return retryTransactionWrapper(() => { |
45 | // Maybe the video changed in database, refresh it | 46 | return sequelizeTypescript.transaction(async t => { |
46 | const videoDatabase = await VideoModel.loadFull(video.uuid, t) | 47 | // Maybe the video changed in database, refresh it |
47 | // Video does not exist anymore | 48 | const videoDatabase = await VideoModel.loadFull(video.uuid, t) |
48 | if (!videoDatabase) return undefined | 49 | // Video does not exist anymore |
50 | if (!videoDatabase) return undefined | ||
49 | 51 | ||
50 | // Already in its final state | 52 | // Already in its final state |
51 | if (videoDatabase.state === VideoState.PUBLISHED) { | 53 | if (videoDatabase.state === VideoState.PUBLISHED) { |
52 | return federateVideoIfNeeded(videoDatabase, false, t) | 54 | return federateVideoIfNeeded(videoDatabase, false, t) |
53 | } | 55 | } |
54 | 56 | ||
55 | const newState = buildNextVideoState(videoDatabase.state) | 57 | const newState = buildNextVideoState(videoDatabase.state) |
56 | 58 | ||
57 | if (newState === VideoState.PUBLISHED) { | 59 | if (newState === VideoState.PUBLISHED) { |
58 | return moveToPublishedState({ video: videoDatabase, previousVideoState, isNewVideo, transaction: t }) | 60 | return moveToPublishedState({ video: videoDatabase, previousVideoState, isNewVideo, transaction: t }) |
59 | } | 61 | } |
60 | 62 | ||
61 | if (newState === VideoState.TO_MOVE_TO_EXTERNAL_STORAGE) { | 63 | if (newState === VideoState.TO_MOVE_TO_EXTERNAL_STORAGE) { |
62 | return moveToExternalStorageState({ video: videoDatabase, isNewVideo, transaction: t }) | 64 | return moveToExternalStorageState({ video: videoDatabase, isNewVideo, transaction: t }) |
63 | } | 65 | } |
66 | }) | ||
64 | }) | 67 | }) |
65 | } | 68 | } |
66 | 69 | ||