mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-04 02:09:37 +02:00
Correctly save transaction with retries
This commit is contained in:
parent
fbee171a0b
commit
89e3951587
2 changed files with 13 additions and 2 deletions
|
@ -68,10 +68,20 @@ function transactionRetryer <T> (func: (err: any, data: T) => any) {
|
|||
})
|
||||
}
|
||||
|
||||
function saveInTransactionWithRetries <T extends Pick<Model, 'save'>> (model: T) {
|
||||
function saveInTransactionWithRetries <T extends Pick<Model, 'save' | 'changed'>> (model: T) {
|
||||
const changedKeys = model.changed()
|
||||
if (!changedKeys) throw new Error('No changed keys found')
|
||||
|
||||
return retryTransactionWrapper(() => {
|
||||
return sequelizeTypescript.transaction(async transaction => {
|
||||
await model.save({ transaction })
|
||||
try {
|
||||
await model.save({ transaction })
|
||||
} catch {
|
||||
// Reinit changed keys
|
||||
for (const key of changedKeys) {
|
||||
model.changed(key as keyof Model, true)
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue