Fix fk error when generating storyboard

This commit is contained in:
Chocobozzz 2023-07-26 09:25:21 +02:00
parent 89b9eab5a7
commit 93fd6f3b18
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
2 changed files with 32 additions and 15 deletions

View File

@ -1,10 +1,13 @@
import { Job } from 'bullmq' import { Job } from 'bullmq'
import { join } from 'path' import { join } from 'path'
import { retryTransactionWrapper } from '@server/helpers/database-utils'
import { getFFmpegCommandWrapperOptions } from '@server/helpers/ffmpeg' import { getFFmpegCommandWrapperOptions } from '@server/helpers/ffmpeg'
import { generateImageFilename, getImageSize } from '@server/helpers/image-utils' import { generateImageFilename, getImageSize } from '@server/helpers/image-utils'
import { logger, loggerTagsFactory } from '@server/helpers/logger' import { logger, loggerTagsFactory } from '@server/helpers/logger'
import { deleteFileAndCatch } from '@server/helpers/utils'
import { CONFIG } from '@server/initializers/config' import { CONFIG } from '@server/initializers/config'
import { STORYBOARD } from '@server/initializers/constants' import { STORYBOARD } from '@server/initializers/constants'
import { sequelizeTypescript } from '@server/initializers/database'
import { federateVideoIfNeeded } from '@server/lib/activitypub/videos' import { federateVideoIfNeeded } from '@server/lib/activitypub/videos'
import { VideoPathManager } from '@server/lib/video-path-manager' import { VideoPathManager } from '@server/lib/video-path-manager'
import { StoryboardModel } from '@server/models/video/storyboard' import { StoryboardModel } from '@server/models/video/storyboard'
@ -75,25 +78,39 @@ async function processGenerateStoryboard (job: Job): Promise<void> {
const imageSize = await getImageSize(destination) const imageSize = await getImageSize(destination)
const existing = await StoryboardModel.loadByVideo(video.id) await retryTransactionWrapper(() => {
if (existing) await existing.destroy() return sequelizeTypescript.transaction(async transaction => {
const videoStillExists = await VideoModel.load(video.id, transaction)
if (!videoStillExists) {
logger.info('Video %s does not exist anymore, skipping storyboard generation.', payload.videoUUID, lTags)
deleteFileAndCatch(destination)
return
}
await StoryboardModel.create({ const existing = await StoryboardModel.loadByVideo(video.id, transaction)
filename, if (existing) await existing.destroy({ transaction })
totalHeight: imageSize.height,
totalWidth: imageSize.width, await StoryboardModel.create({
spriteHeight: STORYBOARD.SPRITE_SIZE.height, filename,
spriteWidth: STORYBOARD.SPRITE_SIZE.width, totalHeight: imageSize.height,
spriteDuration, totalWidth: imageSize.width,
videoId: video.id spriteHeight: STORYBOARD.SPRITE_SIZE.height,
spriteWidth: STORYBOARD.SPRITE_SIZE.width,
spriteDuration,
videoId: video.id
}, { transaction })
logger.info('Storyboard generation %s ended for video %s.', destination, video.uuid, lTags)
if (payload.federate) {
await federateVideoIfNeeded(video, false, transaction)
}
})
}) })
logger.info('Storyboard generation %s ended for video %s.', destination, video.uuid, lTags)
}) })
if (payload.federate) {
await federateVideoIfNeeded(video, false)
}
} finally { } finally {
inputFileMutexReleaser() inputFileMutexReleaser()
} }

View File

@ -59,7 +59,7 @@ export class StoryboardModel extends Model<Partial<AttributesOnly<StoryboardMode
@BelongsTo(() => VideoModel, { @BelongsTo(() => VideoModel, {
foreignKey: { foreignKey: {
allowNull: true allowNull: false
}, },
onDelete: 'CASCADE' onDelete: 'CASCADE'
}) })