diff options
Diffstat (limited to 'server/lib')
-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 | } |