Skip to content

Commit

Permalink
feat(getters): add getWorkersCount
Browse files Browse the repository at this point in the history
  • Loading branch information
manast committed Mar 31, 2024
1 parent 55f19e3 commit 743c7aa
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/classes/queue-getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,17 @@ export class QueueGetters<
return this.baseGetClients(matcher);
}

/**
* Returns the current count of workers for the queue.
*
* getWorkersCount(): Promise<number>
*
*/
async getWorkersCount(): Promise<number> {
const workers = await this.getWorkers();
return workers.length;
}

/**
* Get queue events list related to the queue.
* Note: GCP does not support SETNAME, so this call will not work
Expand Down
15 changes: 15 additions & 0 deletions tests/test_getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ describe('Jobs getters', function () {
const nextWorkers = await queue.getWorkers();
expect(nextWorkers).to.have.length(2);

const nextWorkersCount = await queue.getWorkersCount();
expect(nextWorkersCount).to.be.equal(2);

await worker.close();
await worker2.close();
});
Expand All @@ -105,6 +108,9 @@ describe('Jobs getters', function () {
const workers = await queue.getWorkers();
expect(workers).to.have.length(1);

const workersCount = await queue.getWorkersCount();
expect(workersCount).to.be.equal(1);

const worker2 = new Worker(queueName, async () => {}, {
autorun: false,
connection,
Expand All @@ -120,6 +126,9 @@ describe('Jobs getters', function () {
const nextWorkers = await queue.getWorkers();
expect(nextWorkers).to.have.length(2);

const nextWorkersCount = await queue.getWorkersCount();
expect(nextWorkersCount).to.be.equal(2);

const rawnames = nextWorkers.map(nextWorker => {
const workerValues = nextWorker.rawname.split(':');
return workerValues[workerValues.length - 1];
Expand Down Expand Up @@ -160,9 +169,15 @@ describe('Jobs getters', function () {
const workers = await queue.getWorkers();
expect(workers).to.have.length(1);

const workersCount = await queue.getWorkersCount();
expect(workersCount).to.be.equal(1);

const workers2 = await queue2.getWorkers();
expect(workers2).to.have.length(1);

const workersCount2 = await queue2.getWorkersCount();
expect(workersCount2).to.be.equal(1);

await queue2.close();
await worker.close();
await worker2.close();
Expand Down

0 comments on commit 743c7aa

Please sign in to comment.