aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/controllers/api/runners/jobs.ts28
1 files changed, 22 insertions, 6 deletions
diff --git a/server/controllers/api/runners/jobs.ts b/server/controllers/api/runners/jobs.ts
index 3f2a92182..bdeb0c6cd 100644
--- a/server/controllers/api/runners/jobs.ts
+++ b/server/controllers/api/runners/jobs.ts
@@ -1,4 +1,5 @@
1import express, { UploadFiles } from 'express' 1import express, { UploadFiles } from 'express'
2import { retryTransactionWrapper } from '@server/helpers/database-utils'
2import { createReqFiles } from '@server/helpers/express-utils' 3import { createReqFiles } from '@server/helpers/express-utils'
3import { logger, loggerTagsFactory } from '@server/helpers/logger' 4import { logger, loggerTagsFactory } from '@server/helpers/logger'
4import { generateRunnerJobToken } from '@server/helpers/token-generator' 5import { generateRunnerJobToken } from '@server/helpers/token-generator'
@@ -161,14 +162,29 @@ async function acceptRunnerJob (req: express.Request, res: express.Response) {
161 const runner = res.locals.runner 162 const runner = res.locals.runner
162 const runnerJob = res.locals.runnerJob 163 const runnerJob = res.locals.runnerJob
163 164
164 runnerJob.state = RunnerJobState.PROCESSING 165 const newRunnerJob = await retryTransactionWrapper(() => {
165 runnerJob.processingJobToken = generateRunnerJobToken() 166 return sequelizeTypescript.transaction(async transaction => {
166 runnerJob.startedAt = new Date() 167 await runnerJob.reload({ transaction })
167 runnerJob.runnerId = runner.id
168 168
169 const newRunnerJob = await sequelizeTypescript.transaction(transaction => { 169 if (runnerJob.state !== RunnerJobState.PENDING) {
170 return runnerJob.save({ transaction }) 170 res.fail({
171 message: 'This job is not in pending state anymore',
172 status: HttpStatusCode.CONFLICT_409
173 })
174
175 return undefined
176 }
177
178 runnerJob.state = RunnerJobState.PROCESSING
179 runnerJob.processingJobToken = generateRunnerJobToken()
180 runnerJob.startedAt = new Date()
181 runnerJob.runnerId = runner.id
182
183 return runnerJob.save({ transaction })
184 })
171 }) 185 })
186 if (!newRunnerJob) return
187
172 newRunnerJob.Runner = runner as RunnerModel 188 newRunnerJob.Runner = runner as RunnerModel
173 189
174 const result: AcceptRunnerJobResult = { 190 const result: AcceptRunnerJobResult = {