diff options
author | Chocobozzz <me@florianbigard.com> | 2018-07-10 17:02:20 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-07-11 14:00:17 +0200 |
commit | 94831479f5facff9469540a3d49dd347b88bdf5a (patch) | |
tree | 4e8990fc4fded913952c732b6466b15fc52ab06d /server/controllers/api/jobs.ts | |
parent | 2cdf27bae6acfaa0b99bb07555edc57f48b8bc43 (diff) | |
download | PeerTube-94831479f5facff9469540a3d49dd347b88bdf5a.tar.gz PeerTube-94831479f5facff9469540a3d49dd347b88bdf5a.tar.zst PeerTube-94831479f5facff9469540a3d49dd347b88bdf5a.zip |
Migrate to bull
Diffstat (limited to 'server/controllers/api/jobs.ts')
-rw-r--r-- | server/controllers/api/jobs.ts | 25 |
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' |
14 | import { paginationValidator } from '../../middlewares/validators' | 14 | import { paginationValidator } from '../../middlewares/validators' |
15 | import { listJobsValidator } from '../../middlewares/validators/jobs' | 15 | import { listJobsValidator } from '../../middlewares/validators/jobs' |
16 | import { isArray } from '../../helpers/custom-validators/misc' | ||
16 | 17 | ||
17 | const jobsRouter = express.Router() | 18 | const jobsRouter = express.Router() |
18 | 19 | ||
@@ -36,26 +37,30 @@ export { | |||
36 | // --------------------------------------------------------------------------- | 37 | // --------------------------------------------------------------------------- |
37 | 38 | ||
38 | async function listJobs (req: express.Request, res: express.Response, next: express.NextFunction) { | 39 | async 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 | ||
51 | function formatJob (job: any): Job { | 53 | function 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 | } |