aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/hls.ts6
-rw-r--r--server/lib/job-queue/job-queue.ts8
-rw-r--r--server/lib/video-state.ts38
3 files changed, 33 insertions, 19 deletions
diff --git a/server/lib/hls.ts b/server/lib/hls.ts
index 0828a2d0f..8160e7949 100644
--- a/server/lib/hls.ts
+++ b/server/lib/hls.ts
@@ -1,7 +1,7 @@
1import { close, ensureDir, move, open, outputJSON, read, readFile, remove, stat, writeFile } from 'fs-extra' 1import { close, ensureDir, move, open, outputJSON, read, readFile, remove, stat, writeFile } from 'fs-extra'
2import { flatten, uniq } from 'lodash' 2import { flatten, uniq } from 'lodash'
3import { basename, dirname, join } from 'path' 3import { basename, dirname, join } from 'path'
4import { MStreamingPlaylistFilesVideo, MVideoWithFile } from '@server/types/models' 4import { MStreamingPlaylistFilesVideo, MVideo, MVideoUUID } from '@server/types/models'
5import { sha256 } from '../helpers/core-utils' 5import { sha256 } from '../helpers/core-utils'
6import { getAudioStreamCodec, getVideoStreamCodec, getVideoStreamSize } from '../helpers/ffprobe-utils' 6import { getAudioStreamCodec, getVideoStreamCodec, getVideoStreamSize } from '../helpers/ffprobe-utils'
7import { logger } from '../helpers/logger' 7import { logger } from '../helpers/logger'
@@ -31,7 +31,7 @@ async function updateStreamingPlaylistsInfohashesIfNeeded () {
31 } 31 }
32} 32}
33 33
34async function updateMasterHLSPlaylist (video: MVideoWithFile, playlist: MStreamingPlaylistFilesVideo) { 34async function updateMasterHLSPlaylist (video: MVideo, playlist: MStreamingPlaylistFilesVideo) {
35 const masterPlaylists: string[] = [ '#EXTM3U', '#EXT-X-VERSION:3' ] 35 const masterPlaylists: string[] = [ '#EXTM3U', '#EXT-X-VERSION:3' ]
36 36
37 for (const file of playlist.VideoFiles) { 37 for (const file of playlist.VideoFiles) {
@@ -63,7 +63,7 @@ async function updateMasterHLSPlaylist (video: MVideoWithFile, playlist: MStream
63 }) 63 })
64} 64}
65 65
66async function updateSha256VODSegments (video: MVideoWithFile, playlist: MStreamingPlaylistFilesVideo) { 66async function updateSha256VODSegments (video: MVideoUUID, playlist: MStreamingPlaylistFilesVideo) {
67 const json: { [filename: string]: { [range: string]: string } } = {} 67 const json: { [filename: string]: { [range: string]: string } } = {}
68 68
69 // For all the resolutions available for this video 69 // For all the resolutions available for this video
diff --git a/server/lib/job-queue/job-queue.ts b/server/lib/job-queue/job-queue.ts
index 53d6b6a9c..0eab720d9 100644
--- a/server/lib/job-queue/job-queue.ts
+++ b/server/lib/job-queue/job-queue.ts
@@ -108,7 +108,7 @@ class JobQueue {
108 private constructor () { 108 private constructor () {
109 } 109 }
110 110
111 init () { 111 init (produceOnly = false) {
112 // Already initialized 112 // Already initialized
113 if (this.initialized === true) return 113 if (this.initialized === true) return
114 this.initialized = true 114 this.initialized = true
@@ -124,6 +124,12 @@ class JobQueue {
124 124
125 for (const handlerName of (Object.keys(handlers) as JobType[])) { 125 for (const handlerName of (Object.keys(handlers) as JobType[])) {
126 const queue = new Bull(handlerName, queueOptions) 126 const queue = new Bull(handlerName, queueOptions)
127
128 if (produceOnly) {
129 queue.pause(true)
130 .catch(err => logger.error('Cannot pause queue %s in produced only job queue', handlerName, { err }))
131 }
132
127 const handler = handlers[handlerName] 133 const handler = handlers[handlerName]
128 134
129 queue.process(this.getJobConcurrency(handlerName), handler) 135 queue.process(this.getJobConcurrency(handlerName), handler)
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
60async 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
62export { 84export {
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
86async 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}