aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-07-12 16:25:21 +0200
committerChocobozzz <me@florianbigard.com>2022-07-12 16:25:21 +0200
commit4ddb53f65d9d97fc3eb97d9dadcbbcf35d8ddab7 (patch)
treef825afc5453b058d6cc9fd8314812501d8c427bb /server
parent5220859984a9a20c575a294e5825b3e0d756b03b (diff)
downloadPeerTube-4ddb53f65d9d97fc3eb97d9dadcbbcf35d8ddab7.tar.gz
PeerTube-4ddb53f65d9d97fc3eb97d9dadcbbcf35d8ddab7.tar.zst
PeerTube-4ddb53f65d9d97fc3eb97d9dadcbbcf35d8ddab7.zip
Auto retry video state db query on failure
Diffstat (limited to 'server')
-rw-r--r--server/lib/video-state.ts35
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'
9import { federateVideoIfNeeded } from './activitypub/videos' 9import { federateVideoIfNeeded } from './activitypub/videos'
10import { Notifier } from './notifier' 10import { Notifier } from './notifier'
11import { addMoveToObjectStorageJob } from './video' 11import { addMoveToObjectStorageJob } from './video'
12import { retryTransactionWrapper } from '@server/helpers/database-utils'
12 13
13function buildNextVideoState (currentState?: VideoState) { 14function 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