Skip to content

Commit

Permalink
feat(queue): add getJobSchedulersCount method (#2945)
Browse files Browse the repository at this point in the history
  • Loading branch information
manast authored Nov 29, 2024
1 parent b56c3b4 commit 38820dc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/classes/job-scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,11 @@ export class JobScheduler extends QueueBase {
return Promise.all(jobs);
}

async getSchedulersCount(
client: RedisClient,
prefix: string,
queueName: string,
): Promise<number> {
return client.zcard(`${prefix}:${queueName}:repeat`);
async getSchedulersCount(): Promise<number> {
const jobSchedulersKey = this.keys.repeat;
const client = await this.client;

return client.zcard(jobSchedulersKey);
}

private getSchedulerNextJobId({
Expand Down
10 changes: 10 additions & 0 deletions src/classes/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,16 @@ export class Queue<
return (await this.jobScheduler).getJobSchedulers(start, end, asc);
}

/**
*
* Get the number of job schedulers.
*
* @returns The number of job schedulers.
*/
async getJobSchedulersCount(): Promise<number> {
return (await this.jobScheduler).getSchedulersCount();
}

/**
* Removes a repeatable job.
*
Expand Down
3 changes: 3 additions & 0 deletions tests/test_job_scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ describe('Job Scheduler', function () {

const delayed = await queue.getDelayed();
expect(delayed).to.have.length(3);

const jobSchedulersCount = await queue.getJobSchedulersCount();
expect(jobSchedulersCount).to.be.eql(3);
});
});

Expand Down

0 comments on commit 38820dc

Please sign in to comment.