More robust caption update

Avoid file not found when the transaction is retried
This commit is contained in:
Chocobozzz 2024-09-12 10:52:18 +02:00
parent e18ac0a468
commit da6d0bfe88
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
2 changed files with 11 additions and 5 deletions

View File

@ -17,6 +17,7 @@ import {
listVideoCaptionsValidator listVideoCaptionsValidator
} from '../../../middlewares/validators/index.js' } from '../../../middlewares/validators/index.js'
import { VideoCaptionModel } from '../../../models/video/video-caption.js' import { VideoCaptionModel } from '../../../models/video/video-caption.js'
import { retryTransactionWrapper } from '@server/helpers/database-utils.js'
const lTags = loggerTagsFactory('api', 'video-caption') const lTags = loggerTagsFactory('api', 'video-caption')
@ -39,7 +40,7 @@ videoCaptionsRouter.put('/:videoId/captions/:captionLanguage',
authenticate, authenticate,
reqVideoCaptionAdd, reqVideoCaptionAdd,
asyncMiddleware(addVideoCaptionValidator), asyncMiddleware(addVideoCaptionValidator),
asyncRetryTransactionMiddleware(createVideoCaption) asyncMiddleware(createVideoCaption)
) )
videoCaptionsRouter.delete('/:videoId/captions/:captionLanguage', videoCaptionsRouter.delete('/:videoId/captions/:captionLanguage',
@ -88,8 +89,10 @@ async function createVideoCaption (req: express.Request, res: express.Response)
automaticallyGenerated: false automaticallyGenerated: false
}) })
await sequelizeTypescript.transaction(async t => { await retryTransactionWrapper(() => {
await federateVideoIfNeeded(video, false, t) return sequelizeTypescript.transaction(async t => {
return federateVideoIfNeeded(video, false, t)
})
}) })
Hooks.runAction('action:api.video-caption.created', { caption: videoCaption, req, res }) Hooks.runAction('action:api.video-caption.created', { caption: videoCaption, req, res })

View File

@ -19,6 +19,7 @@ import { JobQueue } from './job-queue/job-queue.js'
import { Notifier } from './notifier/notifier.js' import { Notifier } from './notifier/notifier.js'
import { TranscriptionJobHandler } from './runners/index.js' import { TranscriptionJobHandler } from './runners/index.js'
import { VideoPathManager } from './video-path-manager.js' import { VideoPathManager } from './video-path-manager.js'
import { retryTransactionWrapper } from '@server/helpers/database-utils.js'
const lTags = loggerTagsFactory('video-caption') const lTags = loggerTagsFactory('video-caption')
@ -39,8 +40,10 @@ export async function createLocalCaption (options: {
await moveAndProcessCaptionFile({ path }, videoCaption) await moveAndProcessCaptionFile({ path }, videoCaption)
await sequelizeTypescript.transaction(async t => { await retryTransactionWrapper(() => {
await VideoCaptionModel.insertOrReplaceLanguage(videoCaption, t) return sequelizeTypescript.transaction(t => {
return VideoCaptionModel.insertOrReplaceLanguage(videoCaption, t)
})
}) })
return Object.assign(videoCaption, { Video: video }) return Object.assign(videoCaption, { Video: video })