diff options
author | Chocobozzz <me@florianbigard.com> | 2023-07-26 09:25:21 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2023-07-26 09:25:21 +0200 |
commit | 93fd6f3b18e1c0009ff6ca9208966ae36af5dafa (patch) | |
tree | c7788fb4ecd190a4ce78bf4f4e6c91b742b2b6f4 /server/lib/job-queue/handlers | |
parent | 89b9eab5a72fd805325a98ae613c3f0f00ab0250 (diff) | |
download | PeerTube-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.ts | 47 |
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 @@ | |||
1 | import { Job } from 'bullmq' | 1 | import { Job } from 'bullmq' |
2 | import { join } from 'path' | 2 | import { join } from 'path' |
3 | import { retryTransactionWrapper } from '@server/helpers/database-utils' | ||
3 | import { getFFmpegCommandWrapperOptions } from '@server/helpers/ffmpeg' | 4 | import { getFFmpegCommandWrapperOptions } from '@server/helpers/ffmpeg' |
4 | import { generateImageFilename, getImageSize } from '@server/helpers/image-utils' | 5 | import { generateImageFilename, getImageSize } from '@server/helpers/image-utils' |
5 | import { logger, loggerTagsFactory } from '@server/helpers/logger' | 6 | import { logger, loggerTagsFactory } from '@server/helpers/logger' |
7 | import { deleteFileAndCatch } from '@server/helpers/utils' | ||
6 | import { CONFIG } from '@server/initializers/config' | 8 | import { CONFIG } from '@server/initializers/config' |
7 | import { STORYBOARD } from '@server/initializers/constants' | 9 | import { STORYBOARD } from '@server/initializers/constants' |
10 | import { sequelizeTypescript } from '@server/initializers/database' | ||
8 | import { federateVideoIfNeeded } from '@server/lib/activitypub/videos' | 11 | import { federateVideoIfNeeded } from '@server/lib/activitypub/videos' |
9 | import { VideoPathManager } from '@server/lib/video-path-manager' | 12 | import { VideoPathManager } from '@server/lib/video-path-manager' |
10 | import { StoryboardModel } from '@server/models/video/storyboard' | 13 | import { 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 | } |