aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/jobs.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api/jobs.ts')
-rw-r--r--server/controllers/api/jobs.ts26
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 @@
1import express from 'express' 1import express from 'express'
2import { Job, JobState, JobType, ResultList, UserRight } from '@shared/models' 2import { HttpStatusCode, Job, JobState, JobType, ResultList, UserRight } from '@shared/models'
3import { isArray } from '../../helpers/custom-validators/misc' 3import { isArray } from '../../helpers/custom-validators/misc'
4import { JobQueue } from '../../lib/job-queue' 4import { JobQueue } from '../../lib/job-queue'
5import { 5import {
@@ -16,6 +16,18 @@ import { listJobsValidator } from '../../middlewares/validators/jobs'
16 16
17const jobsRouter = express.Router() 17const jobsRouter = express.Router()
18 18
19jobsRouter.post('/pause',
20 authenticate,
21 ensureUserHasRight(UserRight.MANAGE_JOBS),
22 asyncMiddleware(pauseJobQueue)
23)
24
25jobsRouter.post('/resume',
26 authenticate,
27 ensureUserHasRight(UserRight.MANAGE_JOBS),
28 asyncMiddleware(resumeJobQueue)
29)
30
19jobsRouter.get('/:state?', 31jobsRouter.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
51async function pauseJobQueue (req: express.Request, res: express.Response) {
52 await JobQueue.Instance.pause()
53
54 return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
55}
56
57async function resumeJobQueue (req: express.Request, res: express.Response) {
58 await JobQueue.Instance.resume()
59
60 return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
61}
62
39async function listJobs (req: express.Request, res: express.Response) { 63async 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'