aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api')
-rw-r--r--server/controllers/api/jobs.ts25
1 files changed, 15 insertions, 10 deletions
diff --git a/server/controllers/api/jobs.ts b/server/controllers/api/jobs.ts
index aa58a9144..c19596dde 100644
--- a/server/controllers/api/jobs.ts
+++ b/server/controllers/api/jobs.ts
@@ -13,6 +13,7 @@ import {
13} from '../../middlewares' 13} from '../../middlewares'
14import { paginationValidator } from '../../middlewares/validators' 14import { paginationValidator } from '../../middlewares/validators'
15import { listJobsValidator } from '../../middlewares/validators/jobs' 15import { listJobsValidator } from '../../middlewares/validators/jobs'
16import { isArray } from '../../helpers/custom-validators/misc'
16 17
17const jobsRouter = express.Router() 18const jobsRouter = express.Router()
18 19
@@ -36,26 +37,30 @@ export {
36// --------------------------------------------------------------------------- 37// ---------------------------------------------------------------------------
37 38
38async function listJobs (req: express.Request, res: express.Response, next: express.NextFunction) { 39async function listJobs (req: express.Request, res: express.Response, next: express.NextFunction) {
39 const sort = req.query.sort === 'createdAt' ? 'ASC' : 'DESC' 40 const state: JobState = req.params.state
41 const asc = req.query.sort === 'createdAt'
40 42
41 const jobs = await JobQueue.Instance.listForApi(req.params.state, req.query.start, req.query.count, sort) 43 const jobs = await JobQueue.Instance.listForApi(state, req.query.start, req.query.count, asc)
42 const total = await JobQueue.Instance.count(req.params.state) 44 const total = await JobQueue.Instance.count(state)
43 45
44 const result: ResultList<any> = { 46 const result: ResultList<any> = {
45 total, 47 total,
46 data: jobs.map(j => formatJob(j.toJSON())) 48 data: jobs.map(j => formatJob(j, state))
47 } 49 }
48 return res.json(result) 50 return res.json(result)
49} 51}
50 52
51function formatJob (job: any): Job { 53function formatJob (job: any, state: JobState): Job {
54 const error = isArray(job.stacktrace) && job.stacktrace.length !== 0 ? job.stacktrace[0] : null
55
52 return { 56 return {
53 id: job.id, 57 id: job.id,
54 state: job.state as JobState, 58 state: state,
55 type: job.type as JobType, 59 type: job.queue.name as JobType,
56 data: job.data, 60 data: job.data,
57 error: job.error, 61 error,
58 createdAt: new Date(parseInt(job.created_at, 10)), 62 createdAt: new Date(job.timestamp),
59 updatedAt: new Date(parseInt(job.updated_at, 10)) 63 finishedOn: new Date(job.finishedOn),
64 processedOn: new Date(job.processedOn)
60 } 65 }
61} 66}