Skip to content

Commit

Permalink
refactor: extract common job manipulation to a function
Browse files Browse the repository at this point in the history
  • Loading branch information
felixmosh committed Mar 28, 2024
1 parent fc86644 commit 95f7cfa
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions packages/api/src/queueAdapters/bull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,11 @@ export class BullAdapter extends BaseAdapter {
}

public getJob(id: string): Promise<Job | undefined | null> {
return this.queue.getJob(id).then((job) => {
if (typeof job?.attemptsMade === 'number') {
job.attemptsMade++;
}
return job;
});
return this.queue.getJob(id).then((job) => job && this.alignJobData(job));
}

public getJobs(jobStatuses: JobStatus<'bull'>[], start?: number, end?: number): Promise<Job[]> {
return this.queue.getJobs(jobStatuses, start, end).then((jobs) =>
jobs.map((job) => {
if (typeof job?.attemptsMade === 'number') {
job.attemptsMade++; // increase to align it with bullMQ behavior
}

return job;
})
);
return this.queue.getJobs(jobStatuses, start, end).then((jobs) => jobs.map(this.alignJobData));
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand Down Expand Up @@ -99,4 +86,11 @@ export class BullAdapter extends BaseAdapter {
STATUSES.paused,
];
}

private alignJobData(job: Job) {
if (typeof job?.attemptsMade === 'number') {
job.attemptsMade++;
}
return job;
}
}

0 comments on commit 95f7cfa

Please sign in to comment.