Skip to content

Commit

Permalink
refactor: change markerCount as optional parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
roggervalf committed Nov 14, 2024
1 parent 1dfa2da commit 63355ca
Showing 2 changed files with 13 additions and 8 deletions.
15 changes: 11 additions & 4 deletions src/classes/job.ts
Original file line number Diff line number Diff line change
@@ -299,11 +299,18 @@ export class Job<
});
}

if (opts.markerCount > 1) {
// minus 1 base marker that is added when calling addJob scripts
const markerCount =
(opts.markerCount
? Math.min(jobInstances.length, opts.markerCount)
: jobInstances.length) - 1;
if (markerCount > 0) {
const markers: (number | string)[] = [];
Array.from(Array(opts.markerCount - 1).keys()).forEach(index => {
markers.push(0, index + 1);
});
Array(markerCount)
.fill(0)
.forEach(index => {
markers.push(0, index + 1);
});
pipeline.zadd(queue.toKey('marker'), ...markers);
}

6 changes: 2 additions & 4 deletions src/interfaces/queue-options.ts
Original file line number Diff line number Diff line change
@@ -84,11 +84,9 @@ export interface QueueOptions extends QueueBaseOptions {

export interface JobBulkOptions {
/**
* Max quantity of base markers to be added. It's recommend to be the same
* as the quantity of worker instances for this specific queue
* @default 1
* Max quantity of base markers to be added.
*/
markerCount: number;
markerCount?: number;
}

/**

0 comments on commit 63355ca

Please sign in to comment.