1
0
Fork 0

Use saveInTransactionWithRetries helper

This commit is contained in:
Chocobozzz 2023-05-19 15:20:12 +02:00
parent d1c64fd970
commit c0b5a5eb4b
No known key found for this signature in database
GPG key ID: 583A612D890159BE

View file

@ -1,5 +1,5 @@
import { throttle } from 'lodash' import { throttle } from 'lodash'
import { retryTransactionWrapper, saveInTransactionWithRetries } from '@server/helpers/database-utils' import { saveInTransactionWithRetries } from '@server/helpers/database-utils'
import { logger, loggerTagsFactory } from '@server/helpers/logger' import { logger, loggerTagsFactory } from '@server/helpers/logger'
import { RUNNER_JOBS } from '@server/initializers/constants' import { RUNNER_JOBS } from '@server/initializers/constants'
import { sequelizeTypescript } from '@server/initializers/database' import { sequelizeTypescript } from '@server/initializers/database'
@ -124,11 +124,7 @@ export abstract class AbstractJobHandler <C, U extends RunnerJobUpdatePayload, S
return return
} }
await retryTransactionWrapper(() => { await saveInTransactionWithRetries(runnerJob)
return sequelizeTypescript.transaction(async transaction => {
return runnerJob.save({ transaction })
})
})
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
@ -184,11 +180,7 @@ export abstract class AbstractJobHandler <C, U extends RunnerJobUpdatePayload, S
runnerJob.setToErrorOrCancel(cancelState) runnerJob.setToErrorOrCancel(cancelState)
await retryTransactionWrapper(() => { await saveInTransactionWithRetries(runnerJob)
return sequelizeTypescript.transaction(async transaction => {
await runnerJob.save({ transaction })
})
})
const children = await RunnerJobModel.listChildrenOf(runnerJob) const children = await RunnerJobModel.listChildrenOf(runnerJob)
for (const child of children) { for (const child of children) {
@ -219,11 +211,7 @@ export abstract class AbstractJobHandler <C, U extends RunnerJobUpdatePayload, S
runnerJob.resetToPending() runnerJob.resetToPending()
await retryTransactionWrapper(() => { await saveInTransactionWithRetries(runnerJob)
return sequelizeTypescript.transaction(async transaction => {
await runnerJob.save({ transaction })
})
})
} }
protected setAbortState (runnerJob: MRunnerJob) { protected setAbortState (runnerJob: MRunnerJob) {
@ -260,11 +248,7 @@ export abstract class AbstractJobHandler <C, U extends RunnerJobUpdatePayload, S
runnerJob.resetToPending() runnerJob.resetToPending()
} }
await retryTransactionWrapper(() => { await saveInTransactionWithRetries(runnerJob)
return sequelizeTypescript.transaction(async transaction => {
await runnerJob.save({ transaction })
})
})
if (runnerJob.state === errorState) { if (runnerJob.state === errorState) {
const children = await RunnerJobModel.listChildrenOf(runnerJob) const children = await RunnerJobModel.listChildrenOf(runnerJob)