diff options
Diffstat (limited to 'server/controllers/api/jobs.ts')
-rw-r--r-- | server/controllers/api/jobs.ts | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/server/controllers/api/jobs.ts b/server/controllers/api/jobs.ts index eebd195b0..c61b7362f 100644 --- a/server/controllers/api/jobs.ts +++ b/server/controllers/api/jobs.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import express from 'express' | 1 | import express from 'express' |
2 | import { Job, JobState, JobType, ResultList, UserRight } from '@shared/models' | 2 | import { HttpStatusCode, Job, JobState, JobType, ResultList, UserRight } from '@shared/models' |
3 | import { isArray } from '../../helpers/custom-validators/misc' | 3 | import { isArray } from '../../helpers/custom-validators/misc' |
4 | import { JobQueue } from '../../lib/job-queue' | 4 | import { JobQueue } from '../../lib/job-queue' |
5 | import { | 5 | import { |
@@ -16,6 +16,18 @@ import { listJobsValidator } from '../../middlewares/validators/jobs' | |||
16 | 16 | ||
17 | const jobsRouter = express.Router() | 17 | const jobsRouter = express.Router() |
18 | 18 | ||
19 | jobsRouter.post('/pause', | ||
20 | authenticate, | ||
21 | ensureUserHasRight(UserRight.MANAGE_JOBS), | ||
22 | asyncMiddleware(pauseJobQueue) | ||
23 | ) | ||
24 | |||
25 | jobsRouter.post('/resume', | ||
26 | authenticate, | ||
27 | ensureUserHasRight(UserRight.MANAGE_JOBS), | ||
28 | asyncMiddleware(resumeJobQueue) | ||
29 | ) | ||
30 | |||
19 | jobsRouter.get('/:state?', | 31 | jobsRouter.get('/:state?', |
20 | openapiOperationDoc({ operationId: 'getJobs' }), | 32 | openapiOperationDoc({ operationId: 'getJobs' }), |
21 | authenticate, | 33 | authenticate, |
@@ -36,6 +48,18 @@ export { | |||
36 | 48 | ||
37 | // --------------------------------------------------------------------------- | 49 | // --------------------------------------------------------------------------- |
38 | 50 | ||
51 | async function pauseJobQueue (req: express.Request, res: express.Response) { | ||
52 | await JobQueue.Instance.pause() | ||
53 | |||
54 | return res.sendStatus(HttpStatusCode.NO_CONTENT_204) | ||
55 | } | ||
56 | |||
57 | async function resumeJobQueue (req: express.Request, res: express.Response) { | ||
58 | await JobQueue.Instance.resume() | ||
59 | |||
60 | return res.sendStatus(HttpStatusCode.NO_CONTENT_204) | ||
61 | } | ||
62 | |||
39 | async function listJobs (req: express.Request, res: express.Response) { | 63 | async function listJobs (req: express.Request, res: express.Response) { |
40 | const state = req.params.state as JobState | 64 | const state = req.params.state as JobState |
41 | const asc = req.query.sort === 'createdAt' | 65 | const asc = req.query.sort === 'createdAt' |