diff options
author | Chocobozzz <me@florianbigard.com> | 2023-05-19 10:10:41 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2023-05-19 10:10:41 +0200 |
commit | 472170b4f923a52cceb595221864eab61d624d5b (patch) | |
tree | d466b9e7b4f0eb54bffb30250f66b604bf907768 | |
parent | 26172955691acd6d7b682647dda6b2109e426c51 (diff) | |
download | PeerTube-472170b4f923a52cceb595221864eab61d624d5b.tar.gz PeerTube-472170b4f923a52cceb595221864eab61d624d5b.tar.zst PeerTube-472170b4f923a52cceb595221864eab61d624d5b.zip |
Avoid aborting completing jobs
-rw-r--r-- | server/helpers/database-utils.ts | 9 | ||||
-rw-r--r-- | server/initializers/constants.ts | 1 | ||||
-rw-r--r-- | server/lib/runners/job-handlers/abstract-job-handler.ts | 13 | ||||
-rw-r--r-- | shared/models/runners/runner-job-state.model.ts | 3 |
4 files changed, 18 insertions, 8 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 | ||
71 | function 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 | ||
73 | function resetSequelizeInstance <T> (instance: Model<T>) { | 81 | function 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 } = { | |||
577 | const RUNNER_JOB_STATES: { [ id in RunnerJobState ]: string } = { | 577 | const 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 @@ | |||
1 | import { throttle } from 'lodash' | 1 | import { throttle } from 'lodash' |
2 | import { retryTransactionWrapper } from '@server/helpers/database-utils' | 2 | import { retryTransactionWrapper, saveInTransactionWithRetries } from '@server/helpers/database-utils' |
3 | import { logger, loggerTagsFactory } from '@server/helpers/logger' | 3 | import { logger, loggerTagsFactory } from '@server/helpers/logger' |
4 | import { RUNNER_JOBS } from '@server/initializers/constants' | 4 | import { RUNNER_JOBS } from '@server/initializers/constants' |
5 | import { sequelizeTypescript } from '@server/initializers/database' | 5 | import { 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 | ||
diff --git a/shared/models/runners/runner-job-state.model.ts b/shared/models/runners/runner-job-state.model.ts index 738db38b7..7ed34b3bf 100644 --- a/shared/models/runners/runner-job-state.model.ts +++ b/shared/models/runners/runner-job-state.model.ts | |||
@@ -6,5 +6,6 @@ export enum RunnerJobState { | |||
6 | WAITING_FOR_PARENT_JOB = 5, | 6 | WAITING_FOR_PARENT_JOB = 5, |
7 | CANCELLED = 6, | 7 | CANCELLED = 6, |
8 | PARENT_ERRORED = 7, | 8 | PARENT_ERRORED = 7, |
9 | PARENT_CANCELLED = 8 | 9 | PARENT_CANCELLED = 8, |
10 | COMPLETING = 9 | ||
10 | } | 11 | } |