diff options
author | Chocobozzz <me@florianbigard.com> | 2023-07-12 11:09:29 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2023-07-12 11:14:59 +0200 |
commit | d87452277407ef6ab3a368d4b0434b8b80eb7a64 (patch) | |
tree | 39a36e6a669f121a60ad4bc6f3a76bb95a047edd /server/middlewares/validators/runners | |
parent | d959b763f089ed4c1087aa4aeb824a8ef6743111 (diff) | |
download | PeerTube-d87452277407ef6ab3a368d4b0434b8b80eb7a64.tar.gz PeerTube-d87452277407ef6ab3a368d4b0434b8b80eb7a64.tar.zst PeerTube-d87452277407ef6ab3a368d4b0434b8b80eb7a64.zip |
Avoid update remote runner error
Diffstat (limited to 'server/middlewares/validators/runners')
-rw-r--r-- | server/middlewares/validators/runners/jobs.ts | 66 |
1 files changed, 34 insertions, 32 deletions
diff --git a/server/middlewares/validators/runners/jobs.ts b/server/middlewares/validators/runners/jobs.ts index 75cc0bdbb..384b209ba 100644 --- a/server/middlewares/validators/runners/jobs.ts +++ b/server/middlewares/validators/runners/jobs.ts | |||
@@ -159,44 +159,46 @@ export const runnerJobGetValidator = [ | |||
159 | } | 159 | } |
160 | ] | 160 | ] |
161 | 161 | ||
162 | export const jobOfRunnerGetValidator = [ | 162 | export function jobOfRunnerGetValidatorFactory (allowedStates: RunnerJobState[]) { |
163 | param('jobUUID').custom(isUUIDValid), | 163 | return [ |
164 | param('jobUUID').custom(isUUIDValid), | ||
164 | 165 | ||
165 | body('runnerToken').custom(isRunnerTokenValid), | 166 | body('runnerToken').custom(isRunnerTokenValid), |
166 | body('jobToken').custom(isRunnerJobTokenValid), | 167 | body('jobToken').custom(isRunnerJobTokenValid), |
167 | 168 | ||
168 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 169 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
169 | if (areValidationErrors(req, res, { tags })) return cleanUpReqFiles(req) | 170 | if (areValidationErrors(req, res, { tags })) return cleanUpReqFiles(req) |
170 | 171 | ||
171 | const runnerJob = await RunnerJobModel.loadByRunnerAndJobTokensWithRunner({ | 172 | const runnerJob = await RunnerJobModel.loadByRunnerAndJobTokensWithRunner({ |
172 | uuid: req.params.jobUUID, | 173 | uuid: req.params.jobUUID, |
173 | runnerToken: req.body.runnerToken, | 174 | runnerToken: req.body.runnerToken, |
174 | jobToken: req.body.jobToken | 175 | jobToken: req.body.jobToken |
175 | }) | 176 | }) |
176 | 177 | ||
177 | if (!runnerJob) { | 178 | if (!runnerJob) { |
178 | cleanUpReqFiles(req) | 179 | cleanUpReqFiles(req) |
179 | 180 | ||
180 | return res.fail({ | 181 | return res.fail({ |
181 | status: HttpStatusCode.NOT_FOUND_404, | 182 | status: HttpStatusCode.NOT_FOUND_404, |
182 | message: 'Unknown runner job', | 183 | message: 'Unknown runner job', |
183 | tags | 184 | tags |
184 | }) | 185 | }) |
185 | } | 186 | } |
186 | 187 | ||
187 | if (runnerJob.state !== RunnerJobState.PROCESSING) { | 188 | if (!allowedStates.includes(runnerJob.state)) { |
188 | cleanUpReqFiles(req) | 189 | cleanUpReqFiles(req) |
189 | 190 | ||
190 | return res.fail({ | 191 | return res.fail({ |
191 | status: HttpStatusCode.BAD_REQUEST_400, | 192 | status: HttpStatusCode.BAD_REQUEST_400, |
192 | type: ServerErrorCode.RUNNER_JOB_NOT_IN_PROCESSING_STATE, | 193 | type: ServerErrorCode.RUNNER_JOB_NOT_IN_PROCESSING_STATE, |
193 | message: 'Job is not in "processing" state', | 194 | message: 'Job is not in "processing" state', |
194 | tags | 195 | tags |
195 | }) | 196 | }) |
196 | } | 197 | } |
197 | 198 | ||
198 | res.locals.runnerJob = runnerJob | 199 | res.locals.runnerJob = runnerJob |
199 | 200 | ||
200 | return next() | 201 | return next() |
201 | } | 202 | } |
202 | ] | 203 | ] |
204 | } | ||