From 9dd5726225cb718d9b3f3e3bf2223ada8274d1ce Mon Sep 17 00:00:00 2001 From: Felix Mosheev <9304194+felixmosh@users.noreply.github.com> Date: Tue, 22 Mar 2022 09:39:01 +0200 Subject: [PATCH] fix: align attemptsMade to the behavior of BullMQ. closes #386 --- packages/api/src/queueAdapters/bull.ts | 14 ++++++++++++-- packages/ui/src/components/JobCard/JobCard.tsx | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/api/src/queueAdapters/bull.ts b/packages/api/src/queueAdapters/bull.ts index 000c620c..ce8f4a00 100644 --- a/packages/api/src/queueAdapters/bull.ts +++ b/packages/api/src/queueAdapters/bull.ts @@ -20,11 +20,21 @@ export class BullAdapter extends BaseAdapter { } public getJob(id: string): Promise { - return this.queue.getJob(id); + return this.queue.getJob(id).then((job) => { + if (typeof job?.attemptsMade === 'number') { + job.attemptsMade++; + } + return job; + }); } public getJobs(jobStatuses: JobStatus[], start?: number, end?: number): Promise { - return this.queue.getJobs(jobStatuses, start, end); + return this.queue.getJobs(jobStatuses, start, end).then((jobs) => + jobs.map((job) => { + job.attemptsMade++; // increase to align it with bullMQ behavior + return job; + }) + ); } // eslint-disable-next-line @typescript-eslint/no-unused-vars diff --git a/packages/ui/src/components/JobCard/JobCard.tsx b/packages/ui/src/components/JobCard/JobCard.tsx index 831478e5..eefa73d6 100644 --- a/packages/ui/src/components/JobCard/JobCard.tsx +++ b/packages/ui/src/components/JobCard/JobCard.tsx @@ -32,7 +32,7 @@ export const JobCard = ({ job, status, actions, readOnlyMode, allowRetries }: Jo

{job.name} - {job.attempts > 0 && attempt #{job.attempts + 1}} + {job.attempts > 1 && attempt #{job.attempts}} {!!job.opts?.repeat?.count && ( repeat {job.opts?.repeat?.count}