More robust caption update
Avoid file not found when the transaction is retried
This commit is contained in:
parent
e18ac0a468
commit
da6d0bfe88
2 changed files with 11 additions and 5 deletions
|
@ -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 })
|
||||
|
|
|
@ -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 })
|
||||
|
|
Loading…
Reference in a new issue