aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/job-queue/handlers
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-08-26 09:18:57 +0200
committerChocobozzz <me@florianbigard.com>2021-08-26 10:01:42 +0200
commit5a298a5a3d000f94c944d3711d4b0226a888df04 (patch)
treeda5a0baa5ad9e793976277f67926ae6f6fb2e3ec /server/lib/job-queue/handlers
parent18305950c3ff2da9011283ce3e98b087e203bd91 (diff)
downloadPeerTube-5a298a5a3d000f94c944d3711d4b0226a888df04.tar.gz
PeerTube-5a298a5a3d000f94c944d3711d4b0226a888df04.tar.zst
PeerTube-5a298a5a3d000f94c944d3711d4b0226a888df04.zip
Better logs for transcoding
Diffstat (limited to 'server/lib/job-queue/handlers')
-rw-r--r--server/lib/job-queue/handlers/video-transcoding.ts41
1 files changed, 28 insertions, 13 deletions
diff --git a/server/lib/job-queue/handlers/video-transcoding.ts b/server/lib/job-queue/handlers/video-transcoding.ts
index b3149dde8..5a93c4ed1 100644
--- a/server/lib/job-queue/handlers/video-transcoding.ts
+++ b/server/lib/job-queue/handlers/video-transcoding.ts
@@ -15,7 +15,7 @@ import {
15} from '../../../../shared' 15} from '../../../../shared'
16import { retryTransactionWrapper } from '../../../helpers/database-utils' 16import { retryTransactionWrapper } from '../../../helpers/database-utils'
17import { computeResolutionsToTranscode } from '../../../helpers/ffprobe-utils' 17import { computeResolutionsToTranscode } from '../../../helpers/ffprobe-utils'
18import { logger } from '../../../helpers/logger' 18import { logger, loggerTagsFactory } from '../../../helpers/logger'
19import { CONFIG } from '../../../initializers/config' 19import { CONFIG } from '../../../initializers/config'
20import { VideoModel } from '../../../models/video/video' 20import { VideoModel } from '../../../models/video/video'
21import { 21import {
@@ -34,14 +34,16 @@ const handlers: { [ id in VideoTranscodingPayload['type'] ]: HandlerFunction } =
34 'optimize-to-webtorrent': handleWebTorrentOptimizeJob 34 'optimize-to-webtorrent': handleWebTorrentOptimizeJob
35} 35}
36 36
37const lTags = loggerTagsFactory('transcoding')
38
37async function processVideoTranscoding (job: Bull.Job) { 39async function processVideoTranscoding (job: Bull.Job) {
38 const payload = job.data as VideoTranscodingPayload 40 const payload = job.data as VideoTranscodingPayload
39 logger.info('Processing video file in job %d.', job.id) 41 logger.info('Processing transcoding job %d.', job.id, lTags(payload.videoUUID))
40 42
41 const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(payload.videoUUID) 43 const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(payload.videoUUID)
42 // No video, maybe deleted? 44 // No video, maybe deleted?
43 if (!video) { 45 if (!video) {
44 logger.info('Do not process job %d, video does not exist.', job.id) 46 logger.info('Do not process job %d, video does not exist.', job.id, lTags(payload.videoUUID))
45 return undefined 47 return undefined
46 } 48 }
47 49
@@ -63,6 +65,8 @@ async function processVideoTranscoding (job: Bull.Job) {
63// --------------------------------------------------------------------------- 65// ---------------------------------------------------------------------------
64 66
65async function handleHLSJob (job: Bull.Job, payload: HLSTranscodingPayload, video: MVideoFullLight, user: MUser) { 67async function handleHLSJob (job: Bull.Job, payload: HLSTranscodingPayload, video: MVideoFullLight, user: MUser) {
68 logger.info('Handling HLS transcoding job for %s.', video.uuid, lTags(video.uuid))
69
66 const videoFileInput = payload.copyCodecs 70 const videoFileInput = payload.copyCodecs
67 ? video.getWebTorrentFile(payload.resolution) 71 ? video.getWebTorrentFile(payload.resolution)
68 : video.getMaxQualityFile() 72 : video.getMaxQualityFile()
@@ -80,6 +84,8 @@ async function handleHLSJob (job: Bull.Job, payload: HLSTranscodingPayload, vide
80 }) 84 })
81 }) 85 })
82 86
87 logger.info('HLS transcoding job for %s ended.', video.uuid, lTags(video.uuid))
88
83 await retryTransactionWrapper(onHlsPlaylistGeneration, video, user, payload) 89 await retryTransactionWrapper(onHlsPlaylistGeneration, video, user, payload)
84} 90}
85 91
@@ -89,28 +95,38 @@ async function handleNewWebTorrentResolutionJob (
89 video: MVideoFullLight, 95 video: MVideoFullLight,
90 user: MUserId 96 user: MUserId
91) { 97) {
98 logger.info('Handling WebTorrent transcoding job for %s.', video.uuid, lTags(video.uuid))
99
92 await transcodeNewWebTorrentResolution(video, payload.resolution, payload.isPortraitMode || false, job) 100 await transcodeNewWebTorrentResolution(video, payload.resolution, payload.isPortraitMode || false, job)
93 101
102 logger.info('WebTorrent transcoding job for %s ended.', video.uuid, lTags(video.uuid))
103
94 await retryTransactionWrapper(onNewWebTorrentFileResolution, video, user, payload) 104 await retryTransactionWrapper(onNewWebTorrentFileResolution, video, user, payload)
95} 105}
96 106
97async function handleWebTorrentMergeAudioJob (job: Bull.Job, payload: MergeAudioTranscodingPayload, video: MVideoFullLight, user: MUserId) { 107async function handleWebTorrentMergeAudioJob (job: Bull.Job, payload: MergeAudioTranscodingPayload, video: MVideoFullLight, user: MUserId) {
108 logger.info('Handling merge audio transcoding job for %s.', video.uuid, lTags(video.uuid))
109
98 await mergeAudioVideofile(video, payload.resolution, job) 110 await mergeAudioVideofile(video, payload.resolution, job)
99 111
112 logger.info('Merge audio transcoding job for %s ended.', video.uuid, lTags(video.uuid))
113
100 await retryTransactionWrapper(onVideoFileOptimizer, video, payload, 'video', user) 114 await retryTransactionWrapper(onVideoFileOptimizer, video, payload, 'video', user)
101} 115}
102 116
103async function handleWebTorrentOptimizeJob (job: Bull.Job, payload: OptimizeTranscodingPayload, video: MVideoFullLight, user: MUserId) { 117async function handleWebTorrentOptimizeJob (job: Bull.Job, payload: OptimizeTranscodingPayload, video: MVideoFullLight, user: MUserId) {
118 logger.info('Handling optimize transcoding job for %s.', video.uuid, lTags(video.uuid))
119
104 const { transcodeType } = await optimizeOriginalVideofile(video, video.getMaxQualityFile(), job) 120 const { transcodeType } = await optimizeOriginalVideofile(video, video.getMaxQualityFile(), job)
105 121
122 logger.info('Optimize transcoding job for %s ended.', video.uuid, lTags(video.uuid))
123
106 await retryTransactionWrapper(onVideoFileOptimizer, video, payload, transcodeType, user) 124 await retryTransactionWrapper(onVideoFileOptimizer, video, payload, transcodeType, user)
107} 125}
108 126
109// --------------------------------------------------------------------------- 127// ---------------------------------------------------------------------------
110 128
111async function onHlsPlaylistGeneration (video: MVideoFullLight, user: MUser, payload: HLSTranscodingPayload) { 129async function onHlsPlaylistGeneration (video: MVideoFullLight, user: MUser, payload: HLSTranscodingPayload) {
112 if (video === undefined) return undefined
113
114 if (payload.isMaxQuality && CONFIG.TRANSCODING.WEBTORRENT.ENABLED === false) { 130 if (payload.isMaxQuality && CONFIG.TRANSCODING.WEBTORRENT.ENABLED === false) {
115 // Remove webtorrent files if not enabled 131 // Remove webtorrent files if not enabled
116 for (const file of video.VideoFiles) { 132 for (const file of video.VideoFiles) {
@@ -141,9 +157,6 @@ async function onVideoFileOptimizer (
141 transcodeType: TranscodeOptionsType, 157 transcodeType: TranscodeOptionsType,
142 user: MUserId 158 user: MUserId
143) { 159) {
144 if (videoArg === undefined) return undefined
145
146 // Outside the transaction (IO on disk)
147 const { resolution, isPortraitMode } = await videoArg.getMaxQualityResolution() 160 const { resolution, isPortraitMode } = await videoArg.getMaxQualityResolution()
148 161
149 // Maybe the video changed in database, refresh it 162 // Maybe the video changed in database, refresh it
@@ -241,7 +254,7 @@ async function createLowerResolutionsJobs (options: {
241 254
242 // Create transcoding jobs if there are enabled resolutions 255 // Create transcoding jobs if there are enabled resolutions
243 const resolutionsEnabled = computeResolutionsToTranscode(videoFileResolution, 'vod') 256 const resolutionsEnabled = computeResolutionsToTranscode(videoFileResolution, 'vod')
244 const resolutionCreated: number[] = [] 257 const resolutionCreated: string[] = []
245 258
246 for (const resolution of resolutionsEnabled) { 259 for (const resolution of resolutionsEnabled) {
247 let dataInput: VideoTranscodingPayload 260 let dataInput: VideoTranscodingPayload
@@ -255,6 +268,8 @@ async function createLowerResolutionsJobs (options: {
255 isPortraitMode, 268 isPortraitMode,
256 isNewVideo 269 isNewVideo
257 } 270 }
271
272 resolutionCreated.push('webtorrent-' + resolution)
258 } 273 }
259 274
260 if (CONFIG.TRANSCODING.HLS.ENABLED && type === 'hls') { 275 if (CONFIG.TRANSCODING.HLS.ENABLED && type === 'hls') {
@@ -267,12 +282,12 @@ async function createLowerResolutionsJobs (options: {
267 isMaxQuality: false, 282 isMaxQuality: false,
268 isNewVideo 283 isNewVideo
269 } 284 }
285
286 resolutionCreated.push('hls-' + resolution)
270 } 287 }
271 288
272 if (!dataInput) continue 289 if (!dataInput) continue
273 290
274 resolutionCreated.push(resolution)
275
276 const jobOptions = { 291 const jobOptions = {
277 priority: await getTranscodingJobPriority(user) 292 priority: await getTranscodingJobPriority(user)
278 } 293 }
@@ -281,14 +296,14 @@ async function createLowerResolutionsJobs (options: {
281 } 296 }
282 297
283 if (resolutionCreated.length === 0) { 298 if (resolutionCreated.length === 0) {
284 logger.info('No transcoding jobs created for video %s (no resolutions).', video.uuid) 299 logger.info('No transcoding jobs created for video %s (no resolutions).', video.uuid, lTags(video.uuid))
285 300
286 return false 301 return false
287 } 302 }
288 303
289 logger.info( 304 logger.info(
290 'New resolutions %s transcoding jobs created for video %s and origin file resolution of %d.', type, video.uuid, videoFileResolution, 305 'New resolutions %s transcoding jobs created for video %s and origin file resolution of %d.', type, video.uuid, videoFileResolution,
291 { resolutionCreated } 306 { resolutionCreated, ...lTags(video.uuid) }
292 ) 307 )
293 308
294 return true 309 return true