From 51335c72cf1119a92901edeaa5c7dfc1feef3ca4 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 9 Aug 2022 13:21:18 +0200 Subject: [PATCH] Prevent job failure on concurrent HLS transcoding --- server/lib/hls.ts | 18 +++++++++++------- .../job-queue/handlers/video-transcoding.ts | 2 +- server/lib/job-queue/job-queue.ts | 6 +----- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/server/lib/hls.ts b/server/lib/hls.ts index ad29e4c90..9ec931b4f 100644 --- a/server/lib/hls.ts +++ b/server/lib/hls.ts @@ -35,15 +35,19 @@ async function updateStreamingPlaylistsInfohashesIfNeeded () { } async function updatePlaylistAfterFileChange (video: MVideo, playlist: MStreamingPlaylist) { - let playlistWithFiles = await updateMasterHLSPlaylist(video, playlist) - playlistWithFiles = await updateSha256VODSegments(video, playlist) + try { + let playlistWithFiles = await updateMasterHLSPlaylist(video, playlist) + playlistWithFiles = await updateSha256VODSegments(video, playlist) - // Refresh playlist, operations can take some time - playlistWithFiles = await VideoStreamingPlaylistModel.loadWithVideoAndFiles(playlist.id) - playlistWithFiles.assignP2PMediaLoaderInfoHashes(video, playlistWithFiles.VideoFiles) - await playlistWithFiles.save() + // Refresh playlist, operations can take some time + playlistWithFiles = await VideoStreamingPlaylistModel.loadWithVideoAndFiles(playlist.id) + playlistWithFiles.assignP2PMediaLoaderInfoHashes(video, playlistWithFiles.VideoFiles) + await playlistWithFiles.save() - video.setHLSPlaylist(playlistWithFiles) + video.setHLSPlaylist(playlistWithFiles) + } catch (err) { + logger.info('Cannot update playlist after file change. Maybe due to concurrent transcoding', { err }) + } } // --------------------------------------------------------------------------- diff --git a/server/lib/job-queue/handlers/video-transcoding.ts b/server/lib/job-queue/handlers/video-transcoding.ts index cb2978157..b0e92acf7 100644 --- a/server/lib/job-queue/handlers/video-transcoding.ts +++ b/server/lib/job-queue/handlers/video-transcoding.ts @@ -42,7 +42,7 @@ const lTags = loggerTagsFactory('transcoding') async function processVideoTranscoding (job: Job) { const payload = job.data as VideoTranscodingPayload - logger.info('Processing transcoding job %d.', job.id, lTags(payload.videoUUID)) + logger.info('Processing transcoding job %s.', job.id, lTags(payload.videoUUID)) const video = await VideoModel.loadFull(payload.videoUUID) // No video, maybe deleted? diff --git a/server/lib/job-queue/job-queue.ts b/server/lib/job-queue/job-queue.ts index 14e3a00aa..281e2e51a 100644 --- a/server/lib/job-queue/job-queue.ts +++ b/server/lib/job-queue/job-queue.ts @@ -286,20 +286,16 @@ class JobQueue { async pause () { for (const handlerName of Object.keys(this.workers)) { const worker: Worker = this.workers[handlerName] - const queue: Queue = this.queues[handlerName] await worker.pause() - await queue.pause() } } - async resume () { + resume () { for (const handlerName of Object.keys(this.workers)) { const worker: Worker = this.workers[handlerName] - const queue: Queue = this.queues[handlerName] worker.resume() - await queue.resume() } }