diff options
Diffstat (limited to 'server/controllers/api')
-rw-r--r-- | server/controllers/api/runners/jobs.ts | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/server/controllers/api/runners/jobs.ts b/server/controllers/api/runners/jobs.ts index be5911b53..e9e2ddf49 100644 --- a/server/controllers/api/runners/jobs.ts +++ b/server/controllers/api/runners/jobs.ts | |||
@@ -5,7 +5,7 @@ import { logger, loggerTagsFactory } from '@server/helpers/logger' | |||
5 | import { generateRunnerJobToken } from '@server/helpers/token-generator' | 5 | import { generateRunnerJobToken } from '@server/helpers/token-generator' |
6 | import { MIMETYPES } from '@server/initializers/constants' | 6 | import { MIMETYPES } from '@server/initializers/constants' |
7 | import { sequelizeTypescript } from '@server/initializers/database' | 7 | import { sequelizeTypescript } from '@server/initializers/database' |
8 | import { getRunnerJobHandlerClass, updateLastRunnerContact } from '@server/lib/runners' | 8 | import { getRunnerJobHandlerClass, runnerJobCanBeCancelled, updateLastRunnerContact } from '@server/lib/runners' |
9 | import { | 9 | import { |
10 | apiRateLimiter, | 10 | apiRateLimiter, |
11 | asyncMiddleware, | 11 | asyncMiddleware, |
@@ -23,6 +23,7 @@ import { | |||
23 | errorRunnerJobValidator, | 23 | errorRunnerJobValidator, |
24 | getRunnerFromTokenValidator, | 24 | getRunnerFromTokenValidator, |
25 | jobOfRunnerGetValidatorFactory, | 25 | jobOfRunnerGetValidatorFactory, |
26 | listRunnerJobsValidator, | ||
26 | runnerJobGetValidator, | 27 | runnerJobGetValidator, |
27 | successRunnerJobValidator, | 28 | successRunnerJobValidator, |
28 | updateRunnerJobValidator | 29 | updateRunnerJobValidator |
@@ -131,9 +132,17 @@ runnerJobsRouter.get('/jobs', | |||
131 | runnerJobsSortValidator, | 132 | runnerJobsSortValidator, |
132 | setDefaultSort, | 133 | setDefaultSort, |
133 | setDefaultPagination, | 134 | setDefaultPagination, |
135 | listRunnerJobsValidator, | ||
134 | asyncMiddleware(listRunnerJobs) | 136 | asyncMiddleware(listRunnerJobs) |
135 | ) | 137 | ) |
136 | 138 | ||
139 | runnerJobsRouter.delete('/jobs/:jobUUID', | ||
140 | authenticate, | ||
141 | ensureUserHasRight(UserRight.MANAGE_RUNNERS), | ||
142 | asyncMiddleware(runnerJobGetValidator), | ||
143 | asyncMiddleware(deleteRunnerJob) | ||
144 | ) | ||
145 | |||
137 | // --------------------------------------------------------------------------- | 146 | // --------------------------------------------------------------------------- |
138 | 147 | ||
139 | export { | 148 | export { |
@@ -374,6 +383,21 @@ async function cancelRunnerJob (req: express.Request, res: express.Response) { | |||
374 | return res.sendStatus(HttpStatusCode.NO_CONTENT_204) | 383 | return res.sendStatus(HttpStatusCode.NO_CONTENT_204) |
375 | } | 384 | } |
376 | 385 | ||
386 | async function deleteRunnerJob (req: express.Request, res: express.Response) { | ||
387 | const runnerJob = res.locals.runnerJob | ||
388 | |||
389 | logger.info('Deleting job %s (%s)', runnerJob.uuid, runnerJob.type, lTags(runnerJob.uuid, runnerJob.type)) | ||
390 | |||
391 | if (runnerJobCanBeCancelled(runnerJob)) { | ||
392 | const RunnerJobHandler = getRunnerJobHandlerClass(runnerJob) | ||
393 | await new RunnerJobHandler().cancel({ runnerJob }) | ||
394 | } | ||
395 | |||
396 | await runnerJob.destroy() | ||
397 | |||
398 | return res.sendStatus(HttpStatusCode.NO_CONTENT_204) | ||
399 | } | ||
400 | |||
377 | async function listRunnerJobs (req: express.Request, res: express.Response) { | 401 | async function listRunnerJobs (req: express.Request, res: express.Response) { |
378 | const query: ListRunnerJobsQuery = req.query | 402 | const query: ListRunnerJobsQuery = req.query |
379 | 403 | ||
@@ -381,7 +405,8 @@ async function listRunnerJobs (req: express.Request, res: express.Response) { | |||
381 | start: query.start, | 405 | start: query.start, |
382 | count: query.count, | 406 | count: query.count, |
383 | sort: query.sort, | 407 | sort: query.sort, |
384 | search: query.search | 408 | search: query.search, |
409 | stateOneOf: query.stateOneOf | ||
385 | }) | 410 | }) |
386 | 411 | ||
387 | return res.json({ | 412 | return res.json({ |