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.ts13
1 files changed, 4 insertions, 9 deletions
diff --git a/server/controllers/api/jobs.ts b/server/controllers/api/jobs.ts
index e14ea2575..929140140 100644
--- a/server/controllers/api/jobs.ts
+++ b/server/controllers/api/jobs.ts
@@ -52,28 +52,23 @@ async function listJobs (req: express.Request, res: express.Response) {
52 52
53 const result: ResultList<Job> = { 53 const result: ResultList<Job> = {
54 total, 54 total,
55 data: state 55 data: await Promise.all(jobs.map(j => formatJob(j, state)))
56 ? jobs.map(j => formatJob(j, state))
57 : await Promise.all(jobs.map(j => formatJobWithUnknownState(j)))
58 } 56 }
59 57
60 return res.json(result) 58 return res.json(result)
61} 59}
62 60
63async function formatJobWithUnknownState (job: any) { 61async function formatJob (job: any, state?: JobState): Promise<Job> {
64 return formatJob(job, await job.getState())
65}
66
67function formatJob (job: any, state: JobState): Job {
68 const error = isArray(job.stacktrace) && job.stacktrace.length !== 0 62 const error = isArray(job.stacktrace) && job.stacktrace.length !== 0
69 ? job.stacktrace[0] 63 ? job.stacktrace[0]
70 : null 64 : null
71 65
72 return { 66 return {
73 id: job.id, 67 id: job.id,
74 state: state, 68 state: state || await job.getState(),
75 type: job.queue.name as JobType, 69 type: job.queue.name as JobType,
76 data: job.data, 70 data: job.data,
71 progress: await job.progress(),
77 error, 72 error,
78 createdAt: new Date(job.timestamp), 73 createdAt: new Date(job.timestamp),
79 finishedOn: new Date(job.finishedOn), 74 finishedOn: new Date(job.finishedOn),