diff options
author | Chocobozzz <me@florianbigard.com> | 2022-08-08 15:48:17 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-08-09 09:18:07 +0200 |
commit | bd911b54b555b11df7e9849cf92d358bccfecf6e (patch) | |
tree | 23e94b4acbe6819fedc1cb5e067b700cbdd880c3 /server/lib/video.ts | |
parent | 5a921e7b74910414626bfc9672b857e987e3ebed (diff) | |
download | PeerTube-bd911b54b555b11df7e9849cf92d358bccfecf6e.tar.gz PeerTube-bd911b54b555b11df7e9849cf92d358bccfecf6e.tar.zst PeerTube-bd911b54b555b11df7e9849cf92d358bccfecf6e.zip |
Use bullmq job dependency
Diffstat (limited to 'server/lib/video.ts')
-rw-r--r-- | server/lib/video.ts | 40 |
1 files changed, 24 insertions, 16 deletions
diff --git a/server/lib/video.ts b/server/lib/video.ts index b843b11bc..f7d7aa186 100644 --- a/server/lib/video.ts +++ b/server/lib/video.ts | |||
@@ -1,5 +1,7 @@ | |||
1 | import { UploadFiles } from 'express' | 1 | import { UploadFiles } from 'express' |
2 | import memoizee from 'memoizee' | ||
2 | import { Transaction } from 'sequelize/types' | 3 | import { Transaction } from 'sequelize/types' |
4 | import { CONFIG } from '@server/initializers/config' | ||
3 | import { DEFAULT_AUDIO_RESOLUTION, JOB_PRIORITY, MEMOIZE_LENGTH, MEMOIZE_TTL } from '@server/initializers/constants' | 5 | import { DEFAULT_AUDIO_RESOLUTION, JOB_PRIORITY, MEMOIZE_LENGTH, MEMOIZE_TTL } from '@server/initializers/constants' |
4 | import { TagModel } from '@server/models/video/tag' | 6 | import { TagModel } from '@server/models/video/tag' |
5 | import { VideoModel } from '@server/models/video/video' | 7 | import { VideoModel } from '@server/models/video/video' |
@@ -9,8 +11,6 @@ import { MThumbnail, MUserId, MVideoFile, MVideoTag, MVideoThumbnail, MVideoUUID | |||
9 | import { ThumbnailType, VideoCreate, VideoPrivacy, VideoState, VideoTranscodingPayload } from '@shared/models' | 11 | import { ThumbnailType, VideoCreate, VideoPrivacy, VideoState, VideoTranscodingPayload } from '@shared/models' |
10 | import { CreateJobOptions, JobQueue } from './job-queue/job-queue' | 12 | import { CreateJobOptions, JobQueue } from './job-queue/job-queue' |
11 | import { updateVideoMiniatureFromExisting } from './thumbnail' | 13 | import { updateVideoMiniatureFromExisting } from './thumbnail' |
12 | import { CONFIG } from '@server/initializers/config' | ||
13 | import memoizee from 'memoizee' | ||
14 | 14 | ||
15 | function buildLocalVideoFromReq (videoInfo: VideoCreate, channelId: number): FilteredModelAttributes<VideoModel> { | 15 | function buildLocalVideoFromReq (videoInfo: VideoCreate, channelId: number): FilteredModelAttributes<VideoModel> { |
16 | return { | 16 | return { |
@@ -86,7 +86,7 @@ async function setVideoTags (options: { | |||
86 | 86 | ||
87 | // --------------------------------------------------------------------------- | 87 | // --------------------------------------------------------------------------- |
88 | 88 | ||
89 | async function addOptimizeOrMergeAudioJob (options: { | 89 | async function buildOptimizeOrMergeAudioJob (options: { |
90 | video: MVideoUUID | 90 | video: MVideoUUID |
91 | videoFile: MVideoFile | 91 | videoFile: MVideoFile |
92 | user: MUserId | 92 | user: MUserId |
@@ -94,10 +94,10 @@ async function addOptimizeOrMergeAudioJob (options: { | |||
94 | }) { | 94 | }) { |
95 | const { video, videoFile, user, isNewVideo } = options | 95 | const { video, videoFile, user, isNewVideo } = options |
96 | 96 | ||
97 | let dataInput: VideoTranscodingPayload | 97 | let payload: VideoTranscodingPayload |
98 | 98 | ||
99 | if (videoFile.isAudio()) { | 99 | if (videoFile.isAudio()) { |
100 | dataInput = { | 100 | payload = { |
101 | type: 'merge-audio-to-webtorrent', | 101 | type: 'merge-audio-to-webtorrent', |
102 | resolution: DEFAULT_AUDIO_RESOLUTION, | 102 | resolution: DEFAULT_AUDIO_RESOLUTION, |
103 | videoUUID: video.uuid, | 103 | videoUUID: video.uuid, |
@@ -105,24 +105,26 @@ async function addOptimizeOrMergeAudioJob (options: { | |||
105 | isNewVideo | 105 | isNewVideo |
106 | } | 106 | } |
107 | } else { | 107 | } else { |
108 | dataInput = { | 108 | payload = { |
109 | type: 'optimize-to-webtorrent', | 109 | type: 'optimize-to-webtorrent', |
110 | videoUUID: video.uuid, | 110 | videoUUID: video.uuid, |
111 | isNewVideo | 111 | isNewVideo |
112 | } | 112 | } |
113 | } | 113 | } |
114 | 114 | ||
115 | const jobOptions = { | 115 | await VideoJobInfoModel.increaseOrCreate(payload.videoUUID, 'pendingTranscode') |
116 | priority: await getTranscodingJobPriority(user) | ||
117 | } | ||
118 | 116 | ||
119 | return addTranscodingJob(dataInput, jobOptions) | 117 | return { |
118 | type: 'video-transcoding' as 'video-transcoding', | ||
119 | priority: await getTranscodingJobPriority(user), | ||
120 | payload | ||
121 | } | ||
120 | } | 122 | } |
121 | 123 | ||
122 | async function addTranscodingJob (payload: VideoTranscodingPayload, options: CreateJobOptions = {}) { | 124 | async function addTranscodingJob (payload: VideoTranscodingPayload, options: CreateJobOptions = {}) { |
123 | await VideoJobInfoModel.increaseOrCreate(payload.videoUUID, 'pendingTranscode') | 125 | await VideoJobInfoModel.increaseOrCreate(payload.videoUUID, 'pendingTranscode') |
124 | 126 | ||
125 | return JobQueue.Instance.createJobWithPromise({ type: 'video-transcoding', payload }, options) | 127 | return JobQueue.Instance.createJob({ type: 'video-transcoding', payload, ...options }) |
126 | } | 128 | } |
127 | 129 | ||
128 | async function getTranscodingJobPriority (user: MUserId) { | 130 | async function getTranscodingJobPriority (user: MUserId) { |
@@ -136,7 +138,7 @@ async function getTranscodingJobPriority (user: MUserId) { | |||
136 | 138 | ||
137 | // --------------------------------------------------------------------------- | 139 | // --------------------------------------------------------------------------- |
138 | 140 | ||
139 | async function addMoveToObjectStorageJob (options: { | 141 | async function buildMoveToObjectStorageJob (options: { |
140 | video: MVideoUUID | 142 | video: MVideoUUID |
141 | previousVideoState: VideoState | 143 | previousVideoState: VideoState |
142 | isNewVideo?: boolean // Default true | 144 | isNewVideo?: boolean // Default true |
@@ -145,8 +147,14 @@ async function addMoveToObjectStorageJob (options: { | |||
145 | 147 | ||
146 | await VideoJobInfoModel.increaseOrCreate(video.uuid, 'pendingMove') | 148 | await VideoJobInfoModel.increaseOrCreate(video.uuid, 'pendingMove') |
147 | 149 | ||
148 | const dataInput = { videoUUID: video.uuid, isNewVideo, previousVideoState } | 150 | return { |
149 | return JobQueue.Instance.createJobWithPromise({ type: 'move-to-object-storage', payload: dataInput }) | 151 | type: 'move-to-object-storage' as 'move-to-object-storage', |
152 | payload: { | ||
153 | videoUUID: video.uuid, | ||
154 | isNewVideo, | ||
155 | previousVideoState | ||
156 | } | ||
157 | } | ||
150 | } | 158 | } |
151 | 159 | ||
152 | // --------------------------------------------------------------------------- | 160 | // --------------------------------------------------------------------------- |
@@ -173,9 +181,9 @@ export { | |||
173 | buildLocalVideoFromReq, | 181 | buildLocalVideoFromReq, |
174 | buildVideoThumbnailsFromReq, | 182 | buildVideoThumbnailsFromReq, |
175 | setVideoTags, | 183 | setVideoTags, |
176 | addOptimizeOrMergeAudioJob, | 184 | buildOptimizeOrMergeAudioJob, |
177 | addTranscodingJob, | 185 | addTranscodingJob, |
178 | addMoveToObjectStorageJob, | 186 | buildMoveToObjectStorageJob, |
179 | getTranscodingJobPriority, | 187 | getTranscodingJobPriority, |
180 | getCachedVideoDuration | 188 | getCachedVideoDuration |
181 | } | 189 | } |