aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/runners
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/runners')
-rw-r--r--server/lib/runners/job-handlers/abstract-job-handler.ts22
1 files changed, 14 insertions, 8 deletions
diff --git a/server/lib/runners/job-handlers/abstract-job-handler.ts b/server/lib/runners/job-handlers/abstract-job-handler.ts
index 73fc14574..74b455107 100644
--- a/server/lib/runners/job-handlers/abstract-job-handler.ts
+++ b/server/lib/runners/job-handlers/abstract-job-handler.ts
@@ -21,6 +21,7 @@ import {
21 RunnerJobVODWebVideoTranscodingPayload, 21 RunnerJobVODWebVideoTranscodingPayload,
22 RunnerJobVODWebVideoTranscodingPrivatePayload 22 RunnerJobVODWebVideoTranscodingPrivatePayload
23} from '@shared/models' 23} from '@shared/models'
24import { throttle } from 'lodash'
24 25
25type CreateRunnerJobArg = 26type CreateRunnerJobArg =
26 { 27 {
@@ -48,6 +49,8 @@ export abstract class AbstractJobHandler <C, U extends RunnerJobUpdatePayload, S
48 49
49 protected readonly lTags = loggerTagsFactory('runner') 50 protected readonly lTags = loggerTagsFactory('runner')
50 51
52 static setJobAsUpdatedThrottled = throttle(setAsUpdated, 2000)
53
51 // --------------------------------------------------------------------------- 54 // ---------------------------------------------------------------------------
52 55
53 abstract create (options: C): Promise<MRunnerJob> 56 abstract create (options: C): Promise<MRunnerJob>
@@ -102,16 +105,19 @@ export abstract class AbstractJobHandler <C, U extends RunnerJobUpdatePayload, S
102 105
103 if (progress) runnerJob.progress = progress 106 if (progress) runnerJob.progress = progress
104 107
108 if (!runnerJob.changed()) {
109 try {
110 await AbstractJobHandler.setJobAsUpdatedThrottled({ sequelize: sequelizeTypescript, table: 'runnerJob', id: runnerJob.id })
111 } catch (err) {
112 logger.warn('Cannot set remote job as updated', { err, ...this.lTags(runnerJob.id, runnerJob.type) })
113 }
114
115 return
116 }
117
105 await retryTransactionWrapper(() => { 118 await retryTransactionWrapper(() => {
106 return sequelizeTypescript.transaction(async transaction => { 119 return sequelizeTypescript.transaction(async transaction => {
107 if (runnerJob.changed()) { 120 return runnerJob.save({ transaction })
108 return runnerJob.save({ transaction })
109 }
110
111 // Don't update the job too often
112 if (new Date().getTime() - runnerJob.updatedAt.getTime() > 2000) {
113 await setAsUpdated({ sequelize: sequelizeTypescript, table: 'runnerJob', id: runnerJob.id, transaction })
114 }
115 }) 121 })
116 }) 122 })
117 } 123 }