diff options
Diffstat (limited to 'server/lib/video-state.ts')
-rw-r--r-- | server/lib/video-state.ts | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/server/lib/video-state.ts b/server/lib/video-state.ts index 9352a67d1..d5bbbec43 100644 --- a/server/lib/video-state.ts +++ b/server/lib/video-state.ts | |||
@@ -57,10 +57,33 @@ function moveToNextState (video: MVideoUUID, isNewVideo = true) { | |||
57 | }) | 57 | }) |
58 | } | 58 | } |
59 | 59 | ||
60 | async function moveToExternalStorageState (video: MVideoFullLight, isNewVideo: boolean, transaction: Transaction) { | ||
61 | const videoJobInfo = await VideoJobInfoModel.load(video.id, transaction) | ||
62 | const pendingTranscode = videoJobInfo?.pendingTranscode || 0 | ||
63 | |||
64 | // We want to wait all transcoding jobs before moving the video on an external storage | ||
65 | if (pendingTranscode !== 0) return false | ||
66 | |||
67 | await video.setNewState(VideoState.TO_MOVE_TO_EXTERNAL_STORAGE, isNewVideo, transaction) | ||
68 | |||
69 | logger.info('Creating external storage move job for video %s.', video.uuid, { tags: [ video.uuid ] }) | ||
70 | |||
71 | try { | ||
72 | await addMoveToObjectStorageJob(video, isNewVideo) | ||
73 | |||
74 | return true | ||
75 | } catch (err) { | ||
76 | logger.error('Cannot add move to object storage job', { err }) | ||
77 | |||
78 | return false | ||
79 | } | ||
80 | } | ||
81 | |||
60 | // --------------------------------------------------------------------------- | 82 | // --------------------------------------------------------------------------- |
61 | 83 | ||
62 | export { | 84 | export { |
63 | buildNextVideoState, | 85 | buildNextVideoState, |
86 | moveToExternalStorageState, | ||
64 | moveToNextState | 87 | moveToNextState |
65 | } | 88 | } |
66 | 89 | ||
@@ -82,18 +105,3 @@ async function moveToPublishedState (video: MVideoFullLight, isNewVideo: boolean | |||
82 | Notifier.Instance.notifyOnVideoPublishedAfterTranscoding(video) | 105 | Notifier.Instance.notifyOnVideoPublishedAfterTranscoding(video) |
83 | } | 106 | } |
84 | } | 107 | } |
85 | |||
86 | async function moveToExternalStorageState (video: MVideoFullLight, isNewVideo: boolean, transaction: Transaction) { | ||
87 | const videoJobInfo = await VideoJobInfoModel.load(video.id, transaction) | ||
88 | const pendingTranscode = videoJobInfo?.pendingTranscode || 0 | ||
89 | |||
90 | // We want to wait all transcoding jobs before moving the video on an external storage | ||
91 | if (pendingTranscode !== 0) return | ||
92 | |||
93 | await video.setNewState(VideoState.TO_MOVE_TO_EXTERNAL_STORAGE, isNewVideo, transaction) | ||
94 | |||
95 | logger.info('Creating external storage move job for video %s.', video.uuid, { tags: [ video.uuid ] }) | ||
96 | |||
97 | addMoveToObjectStorageJob(video, isNewVideo) | ||
98 | .catch(err => logger.error('Cannot add move to object storage job', { err })) | ||
99 | } | ||