aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-05-19 10:10:41 +0200
committerChocobozzz <me@florianbigard.com>2023-05-19 10:10:41 +0200
commit472170b4f923a52cceb595221864eab61d624d5b (patch)
treed466b9e7b4f0eb54bffb30250f66b604bf907768 /server
parent26172955691acd6d7b682647dda6b2109e426c51 (diff)
downloadPeerTube-472170b4f923a52cceb595221864eab61d624d5b.tar.gz
PeerTube-472170b4f923a52cceb595221864eab61d624d5b.tar.zst
PeerTube-472170b4f923a52cceb595221864eab61d624d5b.zip
Avoid aborting completing jobs
Diffstat (limited to 'server')
-rw-r--r--server/helpers/database-utils.ts9
-rw-r--r--server/initializers/constants.ts1
-rw-r--r--server/lib/runners/job-handlers/abstract-job-handler.ts13
3 files changed, 16 insertions, 7 deletions
diff --git a/server/helpers/database-utils.ts b/server/helpers/database-utils.ts
index da8fb0d54..b6ba7fd75 100644
--- a/server/helpers/database-utils.ts
+++ b/server/helpers/database-utils.ts
@@ -68,6 +68,14 @@ function transactionRetryer <T> (func: (err: any, data: T) => any) {
68 }) 68 })
69} 69}
70 70
71function saveInTransactionWithRetries <T extends Pick<Model, 'save'>> (model: T) {
72 return retryTransactionWrapper(() => {
73 return sequelizeTypescript.transaction(async transaction => {
74 await model.save({ transaction })
75 })
76 })
77}
78
71// --------------------------------------------------------------------------- 79// ---------------------------------------------------------------------------
72 80
73function resetSequelizeInstance <T> (instance: Model<T>) { 81function resetSequelizeInstance <T> (instance: Model<T>) {
@@ -105,6 +113,7 @@ export {
105 resetSequelizeInstance, 113 resetSequelizeInstance,
106 retryTransactionWrapper, 114 retryTransactionWrapper,
107 transactionRetryer, 115 transactionRetryer,
116 saveInTransactionWithRetries,
108 afterCommitIfTransaction, 117 afterCommitIfTransaction,
109 filterNonExistingModels, 118 filterNonExistingModels,
110 deleteAllModels, 119 deleteAllModels,
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts
index 85944fa3a..ba522c9de 100644
--- a/server/initializers/constants.ts
+++ b/server/initializers/constants.ts
@@ -577,6 +577,7 @@ const VIDEO_PLAYLIST_TYPES: { [ id in VideoPlaylistType ]: string } = {
577const RUNNER_JOB_STATES: { [ id in RunnerJobState ]: string } = { 577const RUNNER_JOB_STATES: { [ id in RunnerJobState ]: string } = {
578 [RunnerJobState.PROCESSING]: 'Processing', 578 [RunnerJobState.PROCESSING]: 'Processing',
579 [RunnerJobState.COMPLETED]: 'Completed', 579 [RunnerJobState.COMPLETED]: 'Completed',
580 [RunnerJobState.COMPLETING]: 'Completing',
580 [RunnerJobState.PENDING]: 'Pending', 581 [RunnerJobState.PENDING]: 'Pending',
581 [RunnerJobState.ERRORED]: 'Errored', 582 [RunnerJobState.ERRORED]: 'Errored',
582 [RunnerJobState.WAITING_FOR_PARENT_JOB]: 'Waiting for parent job to finish', 583 [RunnerJobState.WAITING_FOR_PARENT_JOB]: 'Waiting for parent job to finish',
diff --git a/server/lib/runners/job-handlers/abstract-job-handler.ts b/server/lib/runners/job-handlers/abstract-job-handler.ts
index 28c3e1eda..ca97d0881 100644
--- a/server/lib/runners/job-handlers/abstract-job-handler.ts
+++ b/server/lib/runners/job-handlers/abstract-job-handler.ts
@@ -1,5 +1,5 @@
1import { throttle } from 'lodash' 1import { throttle } from 'lodash'
2import { retryTransactionWrapper } from '@server/helpers/database-utils' 2import { retryTransactionWrapper, saveInTransactionWithRetries } from '@server/helpers/database-utils'
3import { logger, loggerTagsFactory } from '@server/helpers/logger' 3import { logger, loggerTagsFactory } from '@server/helpers/logger'
4import { RUNNER_JOBS } from '@server/initializers/constants' 4import { RUNNER_JOBS } from '@server/initializers/constants'
5import { sequelizeTypescript } from '@server/initializers/database' 5import { sequelizeTypescript } from '@server/initializers/database'
@@ -12,10 +12,10 @@ import {
12 RunnerJobLiveRTMPHLSTranscodingPayload, 12 RunnerJobLiveRTMPHLSTranscodingPayload,
13 RunnerJobLiveRTMPHLSTranscodingPrivatePayload, 13 RunnerJobLiveRTMPHLSTranscodingPrivatePayload,
14 RunnerJobState, 14 RunnerJobState,
15 RunnerJobStudioTranscodingPayload,
15 RunnerJobSuccessPayload, 16 RunnerJobSuccessPayload,
16 RunnerJobType, 17 RunnerJobType,
17 RunnerJobUpdatePayload, 18 RunnerJobUpdatePayload,
18 RunnerJobStudioTranscodingPayload,
19 RunnerJobVideoStudioTranscodingPrivatePayload, 19 RunnerJobVideoStudioTranscodingPrivatePayload,
20 RunnerJobVODAudioMergeTranscodingPayload, 20 RunnerJobVODAudioMergeTranscodingPayload,
21 RunnerJobVODAudioMergeTranscodingPrivatePayload, 21 RunnerJobVODAudioMergeTranscodingPrivatePayload,
@@ -139,6 +139,9 @@ export abstract class AbstractJobHandler <C, U extends RunnerJobUpdatePayload, S
139 }) { 139 }) {
140 const { runnerJob } = options 140 const { runnerJob } = options
141 141
142 runnerJob.state = RunnerJobState.COMPLETING
143 await saveInTransactionWithRetries(runnerJob)
144
142 try { 145 try {
143 await this.specificComplete(options) 146 await this.specificComplete(options)
144 147
@@ -153,11 +156,7 @@ export abstract class AbstractJobHandler <C, U extends RunnerJobUpdatePayload, S
153 runnerJob.progress = null 156 runnerJob.progress = null
154 runnerJob.finishedAt = new Date() 157 runnerJob.finishedAt = new Date()
155 158
156 await retryTransactionWrapper(() => { 159 await saveInTransactionWithRetries(runnerJob)
157 return sequelizeTypescript.transaction(async transaction => {
158 await runnerJob.save({ transaction })
159 })
160 })
161 160
162 const [ affectedCount ] = await RunnerJobModel.updateDependantJobsOf(runnerJob) 161 const [ affectedCount ] = await RunnerJobModel.updateDependantJobsOf(runnerJob)
163 162