X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Fvideo-state.ts;h=0b51f5c6bb3105feb7a68deb2994d0ffeb73b299;hb=597f771f3f2bfe4b1e7234a5760e23f0283e2b29;hp=9352a67d1a9990bf54db33703c79197951555a8a;hpb=efa3fef23ecf4e1c5289f8715de184c272ea49f7;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/video-state.ts b/server/lib/video-state.ts index 9352a67d1..0b51f5c6b 100644 --- a/server/lib/video-state.ts +++ b/server/lib/video-state.ts @@ -57,10 +57,38 @@ function moveToNextState (video: MVideoUUID, isNewVideo = true) { }) } +async function moveToExternalStorageState (video: MVideoFullLight, isNewVideo: boolean, transaction: Transaction) { + const videoJobInfo = await VideoJobInfoModel.load(video.id, transaction) + const pendingTranscode = videoJobInfo?.pendingTranscode || 0 + + // We want to wait all transcoding jobs before moving the video on an external storage + if (pendingTranscode !== 0) return false + + await video.setNewState(VideoState.TO_MOVE_TO_EXTERNAL_STORAGE, isNewVideo, transaction) + + logger.info('Creating external storage move job for video %s.', video.uuid, { tags: [ video.uuid ] }) + + try { + await addMoveToObjectStorageJob(video, isNewVideo) + + return true + } catch (err) { + logger.error('Cannot add move to object storage job', { err }) + + return false + } +} + +function moveToFailedTranscodingState (video: MVideoFullLight) { + return video.setNewState(VideoState.TRANSCODING_FAILED, false, undefined) +} + // --------------------------------------------------------------------------- export { buildNextVideoState, + moveToExternalStorageState, + moveToFailedTranscodingState, moveToNextState } @@ -82,18 +110,3 @@ async function moveToPublishedState (video: MVideoFullLight, isNewVideo: boolean Notifier.Instance.notifyOnVideoPublishedAfterTranscoding(video) } } - -async function moveToExternalStorageState (video: MVideoFullLight, isNewVideo: boolean, transaction: Transaction) { - const videoJobInfo = await VideoJobInfoModel.load(video.id, transaction) - const pendingTranscode = videoJobInfo?.pendingTranscode || 0 - - // We want to wait all transcoding jobs before moving the video on an external storage - if (pendingTranscode !== 0) return - - await video.setNewState(VideoState.TO_MOVE_TO_EXTERNAL_STORAGE, isNewVideo, transaction) - - logger.info('Creating external storage move job for video %s.', video.uuid, { tags: [ video.uuid ] }) - - addMoveToObjectStorageJob(video, isNewVideo) - .catch(err => logger.error('Cannot add move to object storage job', { err })) -}