aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/video.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-08-08 15:48:17 +0200
committerChocobozzz <me@florianbigard.com>2022-08-09 09:18:07 +0200
commitbd911b54b555b11df7e9849cf92d358bccfecf6e (patch)
tree23e94b4acbe6819fedc1cb5e067b700cbdd880c3 /server/lib/video.ts
parent5a921e7b74910414626bfc9672b857e987e3ebed (diff)
downloadPeerTube-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.ts40
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 @@
1import { UploadFiles } from 'express' 1import { UploadFiles } from 'express'
2import memoizee from 'memoizee'
2import { Transaction } from 'sequelize/types' 3import { Transaction } from 'sequelize/types'
4import { CONFIG } from '@server/initializers/config'
3import { DEFAULT_AUDIO_RESOLUTION, JOB_PRIORITY, MEMOIZE_LENGTH, MEMOIZE_TTL } from '@server/initializers/constants' 5import { DEFAULT_AUDIO_RESOLUTION, JOB_PRIORITY, MEMOIZE_LENGTH, MEMOIZE_TTL } from '@server/initializers/constants'
4import { TagModel } from '@server/models/video/tag' 6import { TagModel } from '@server/models/video/tag'
5import { VideoModel } from '@server/models/video/video' 7import { VideoModel } from '@server/models/video/video'
@@ -9,8 +11,6 @@ import { MThumbnail, MUserId, MVideoFile, MVideoTag, MVideoThumbnail, MVideoUUID
9import { ThumbnailType, VideoCreate, VideoPrivacy, VideoState, VideoTranscodingPayload } from '@shared/models' 11import { ThumbnailType, VideoCreate, VideoPrivacy, VideoState, VideoTranscodingPayload } from '@shared/models'
10import { CreateJobOptions, JobQueue } from './job-queue/job-queue' 12import { CreateJobOptions, JobQueue } from './job-queue/job-queue'
11import { updateVideoMiniatureFromExisting } from './thumbnail' 13import { updateVideoMiniatureFromExisting } from './thumbnail'
12import { CONFIG } from '@server/initializers/config'
13import memoizee from 'memoizee'
14 14
15function buildLocalVideoFromReq (videoInfo: VideoCreate, channelId: number): FilteredModelAttributes<VideoModel> { 15function 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
89async function addOptimizeOrMergeAudioJob (options: { 89async 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
122async function addTranscodingJob (payload: VideoTranscodingPayload, options: CreateJobOptions = {}) { 124async 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
128async function getTranscodingJobPriority (user: MUserId) { 130async function getTranscodingJobPriority (user: MUserId) {
@@ -136,7 +138,7 @@ async function getTranscodingJobPriority (user: MUserId) {
136 138
137// --------------------------------------------------------------------------- 139// ---------------------------------------------------------------------------
138 140
139async function addMoveToObjectStorageJob (options: { 141async 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}