mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 02:39:33 +02:00
Relax transaction level
We don't need serializable level
This commit is contained in:
parent
bbe4910247
commit
9373f571be
2 changed files with 25 additions and 33 deletions
|
@ -10,7 +10,7 @@ function retryTransactionWrapper <T, A, B, C, D> (
|
||||||
arg1: A,
|
arg1: A,
|
||||||
arg2: B,
|
arg2: B,
|
||||||
arg3: C,
|
arg3: C,
|
||||||
arg4: D,
|
arg4: D
|
||||||
): Promise<T>
|
): Promise<T>
|
||||||
|
|
||||||
function retryTransactionWrapper<T, A, B, C> (
|
function retryTransactionWrapper<T, A, B, C> (
|
||||||
|
@ -45,7 +45,7 @@ function retryTransactionWrapper <T> (
|
||||||
.catch(err => callback(err))
|
.catch(err => callback(err))
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
logger.warn(`Cannot execute ${functionToRetry.name} with many retries.`, { err })
|
logger.warn(`Cannot execute ${functionToRetry.name || 'function'} with many retries.`, { err })
|
||||||
throw err
|
throw err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ function transactionRetryer <T> (func: (err: any, data: T) => any) {
|
||||||
times: 5,
|
times: 5,
|
||||||
|
|
||||||
errorFilter: err => {
|
errorFilter: err => {
|
||||||
const willRetry = (err.name === 'SequelizeDatabaseError')
|
const willRetry = err.name === 'SequelizeDatabaseError'
|
||||||
logger.debug('Maybe retrying the transaction function.', { willRetry, err, tags: [ 'sql', 'retry' ] })
|
logger.debug('Maybe retrying the transaction function.', { willRetry, err, tags: [ 'sql', 'retry' ] })
|
||||||
return willRetry
|
return willRetry
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
import { RunnerJobState, RunnerJobStateType } from '@peertube/peertube-models'
|
import { RunnerJobState, RunnerJobStateType } from '@peertube/peertube-models'
|
||||||
import { retryTransactionWrapper } from '@server/helpers/database-utils.js'
|
import { runInReadCommittedTransaction } from '@server/helpers/database-utils.js'
|
||||||
import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
|
import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
|
||||||
import { RUNNER_JOBS } from '@server/initializers/constants.js'
|
import { RUNNER_JOBS } from '@server/initializers/constants.js'
|
||||||
import { sequelizeTypescript } from '@server/initializers/database.js'
|
|
||||||
import { MRunner, MRunnerJob } from '@server/types/models/runners/index.js'
|
import { MRunner, MRunnerJob } from '@server/types/models/runners/index.js'
|
||||||
import express from 'express'
|
import express from 'express'
|
||||||
|
|
||||||
|
@ -10,7 +9,7 @@ const lTags = loggerTagsFactory('runner')
|
||||||
|
|
||||||
const updatingRunner = new Set<number>()
|
const updatingRunner = new Set<number>()
|
||||||
|
|
||||||
function updateLastRunnerContact (req: express.Request, runner: MRunner) {
|
export function updateLastRunnerContact (req: express.Request, runner: MRunner) {
|
||||||
const now = new Date()
|
const now = new Date()
|
||||||
|
|
||||||
// Don't update last runner contact too often
|
// Don't update last runner contact too often
|
||||||
|
@ -24,15 +23,13 @@ function updateLastRunnerContact (req: express.Request, runner: MRunner) {
|
||||||
|
|
||||||
logger.debug('Updating last runner contact for %s', runner.name, lTags(runner.name))
|
logger.debug('Updating last runner contact for %s', runner.name, lTags(runner.name))
|
||||||
|
|
||||||
retryTransactionWrapper(() => {
|
return runInReadCommittedTransaction(async transaction => {
|
||||||
return sequelizeTypescript.transaction(async transaction => {
|
|
||||||
return runner.save({ transaction })
|
return runner.save({ transaction })
|
||||||
})
|
|
||||||
}).catch(err => logger.error('Cannot update last runner contact for %s', runner.name, { err, ...lTags(runner.name) }))
|
}).catch(err => logger.error('Cannot update last runner contact for %s', runner.name, { err, ...lTags(runner.name) }))
|
||||||
.finally(() => updatingRunner.delete(runner.id))
|
.finally(() => updatingRunner.delete(runner.id))
|
||||||
}
|
}
|
||||||
|
|
||||||
function runnerJobCanBeCancelled (runnerJob: MRunnerJob) {
|
export function runnerJobCanBeCancelled (runnerJob: MRunnerJob) {
|
||||||
const allowedStates = new Set<RunnerJobStateType>([
|
const allowedStates = new Set<RunnerJobStateType>([
|
||||||
RunnerJobState.PENDING,
|
RunnerJobState.PENDING,
|
||||||
RunnerJobState.PROCESSING,
|
RunnerJobState.PROCESSING,
|
||||||
|
@ -41,8 +38,3 @@ function runnerJobCanBeCancelled (runnerJob: MRunnerJob) {
|
||||||
|
|
||||||
return allowedStates.has(runnerJob.state)
|
return allowedStates.has(runnerJob.state)
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
|
||||||
updateLastRunnerContact,
|
|
||||||
runnerJobCanBeCancelled
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue