aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/job-queue/handlers
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-07-26 09:25:21 +0200
committerChocobozzz <me@florianbigard.com>2023-07-26 09:25:21 +0200
commit93fd6f3b18e1c0009ff6ca9208966ae36af5dafa (patch)
treec7788fb4ecd190a4ce78bf4f4e6c91b742b2b6f4 /server/lib/job-queue/handlers
parent89b9eab5a72fd805325a98ae613c3f0f00ab0250 (diff)
downloadPeerTube-93fd6f3b18e1c0009ff6ca9208966ae36af5dafa.tar.gz
PeerTube-93fd6f3b18e1c0009ff6ca9208966ae36af5dafa.tar.zst
PeerTube-93fd6f3b18e1c0009ff6ca9208966ae36af5dafa.zip
Fix fk error when generating storyboard
Diffstat (limited to 'server/lib/job-queue/handlers')
-rw-r--r--server/lib/job-queue/handlers/generate-storyboard.ts47
1 files changed, 32 insertions, 15 deletions
diff --git a/server/lib/job-queue/handlers/generate-storyboard.ts b/server/lib/job-queue/handlers/generate-storyboard.ts
index ec07c568c..169b5ef2d 100644
--- a/server/lib/job-queue/handlers/generate-storyboard.ts
+++ b/server/lib/job-queue/handlers/generate-storyboard.ts
@@ -1,10 +1,13 @@
1import { Job } from 'bullmq' 1import { Job } from 'bullmq'
2import { join } from 'path' 2import { join } from 'path'
3import { retryTransactionWrapper } from '@server/helpers/database-utils'
3import { getFFmpegCommandWrapperOptions } from '@server/helpers/ffmpeg' 4import { getFFmpegCommandWrapperOptions } from '@server/helpers/ffmpeg'
4import { generateImageFilename, getImageSize } from '@server/helpers/image-utils' 5import { generateImageFilename, getImageSize } from '@server/helpers/image-utils'
5import { logger, loggerTagsFactory } from '@server/helpers/logger' 6import { logger, loggerTagsFactory } from '@server/helpers/logger'
7import { deleteFileAndCatch } from '@server/helpers/utils'
6import { CONFIG } from '@server/initializers/config' 8import { CONFIG } from '@server/initializers/config'
7import { STORYBOARD } from '@server/initializers/constants' 9import { STORYBOARD } from '@server/initializers/constants'
10import { sequelizeTypescript } from '@server/initializers/database'
8import { federateVideoIfNeeded } from '@server/lib/activitypub/videos' 11import { federateVideoIfNeeded } from '@server/lib/activitypub/videos'
9import { VideoPathManager } from '@server/lib/video-path-manager' 12import { VideoPathManager } from '@server/lib/video-path-manager'
10import { StoryboardModel } from '@server/models/video/storyboard' 13import { StoryboardModel } from '@server/models/video/storyboard'
@@ -75,25 +78,39 @@ async function processGenerateStoryboard (job: Job): Promise<void> {
75 78
76 const imageSize = await getImageSize(destination) 79 const imageSize = await getImageSize(destination)
77 80
78 const existing = await StoryboardModel.loadByVideo(video.id) 81 await retryTransactionWrapper(() => {
79 if (existing) await existing.destroy() 82 return sequelizeTypescript.transaction(async transaction => {
80 83 const videoStillExists = await VideoModel.load(video.id, transaction)
81 await StoryboardModel.create({ 84 if (!videoStillExists) {
82 filename, 85 logger.info('Video %s does not exist anymore, skipping storyboard generation.', payload.videoUUID, lTags)
83 totalHeight: imageSize.height, 86 deleteFileAndCatch(destination)
84 totalWidth: imageSize.width, 87 return
85 spriteHeight: STORYBOARD.SPRITE_SIZE.height, 88 }
86 spriteWidth: STORYBOARD.SPRITE_SIZE.width, 89
87 spriteDuration, 90 const existing = await StoryboardModel.loadByVideo(video.id, transaction)
88 videoId: video.id 91 if (existing) await existing.destroy({ transaction })
92
93 await StoryboardModel.create({
94 filename,
95 totalHeight: imageSize.height,
96 totalWidth: imageSize.width,
97 spriteHeight: STORYBOARD.SPRITE_SIZE.height,
98 spriteWidth: STORYBOARD.SPRITE_SIZE.width,
99 spriteDuration,
100 videoId: video.id
101 }, { transaction })
102
103 logger.info('Storyboard generation %s ended for video %s.', destination, video.uuid, lTags)
104
105 if (payload.federate) {
106 await federateVideoIfNeeded(video, false, transaction)
107 }
108 })
89 }) 109 })
90 110
91 logger.info('Storyboard generation %s ended for video %s.', destination, video.uuid, lTags)
92 }) 111 })
93 112
94 if (payload.federate) { 113
95 await federateVideoIfNeeded(video, false)
96 }
97 } finally { 114 } finally {
98 inputFileMutexReleaser() 115 inputFileMutexReleaser()
99 } 116 }