1
0
Fork 0

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
} from '../../../middlewares/validators/index.js'
import { VideoCaptionModel } from '../../../models/video/video-caption.js'
import { retryTransactionWrapper } from '@server/helpers/database-utils.js'
const lTags = loggerTagsFactory('api', 'video-caption')
@ -39,7 +40,7 @@ videoCaptionsRouter.put('/:videoId/captions/:captionLanguage',
authenticate,
reqVideoCaptionAdd,
asyncMiddleware(addVideoCaptionValidator),
asyncRetryTransactionMiddleware(createVideoCaption)
asyncMiddleware(createVideoCaption)
)
videoCaptionsRouter.delete('/:videoId/captions/:captionLanguage',
@ -88,8 +89,10 @@ async function createVideoCaption (req: express.Request, res: express.Response)
automaticallyGenerated: false
})
await sequelizeTypescript.transaction(async t => {
await federateVideoIfNeeded(video, false, t)
await retryTransactionWrapper(() => {
return sequelizeTypescript.transaction(async t => {
return federateVideoIfNeeded(video, false, t)
})
})
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 { TranscriptionJobHandler } from './runners/index.js'
import { VideoPathManager } from './video-path-manager.js'
import { retryTransactionWrapper } from '@server/helpers/database-utils.js'
const lTags = loggerTagsFactory('video-caption')
@ -39,8 +40,10 @@ export async function createLocalCaption (options: {
await moveAndProcessCaptionFile({ path }, videoCaption)
await sequelizeTypescript.transaction(async t => {
await VideoCaptionModel.insertOrReplaceLanguage(videoCaption, t)
await retryTransactionWrapper(() => {
return sequelizeTypescript.transaction(t => {
return VideoCaptionModel.insertOrReplaceLanguage(videoCaption, t)
})
})
return Object.assign(videoCaption, { Video: video })