diff --git a/src/classes/worker.ts b/src/classes/worker.ts index f354c94253..05146e9f7b 100644 --- a/src/classes/worker.ts +++ b/src/classes/worker.ts @@ -180,6 +180,7 @@ export class Worker< >>; private blockingConnection: RedisConnection; private blockUntil = 0; + private _concurrency: number; private childPool: ChildPool; private drained: boolean = false; private extendLocksTimer: NodeJS.Timeout | null = null; @@ -392,7 +393,11 @@ export class Worker< ) { throw new Error('concurrency must be a finite number greater than 0'); } - this.opts.concurrency = concurrency; + this._concurrency = concurrency; + } + + get concurrency() { + return this._concurrency; } get repeat(): Promise { @@ -466,7 +471,7 @@ export class Worker< */ while ( !this.waiting && - numTotal < this.opts.concurrency && + numTotal < this._concurrency && (!this.limitUntil || numTotal == 0) ) { const token = `${this.id}:${tokenPostfix++}`; @@ -519,7 +524,7 @@ export class Worker< this.processJob( >job, token, - () => asyncFifoQueue.numTotal() <= this.opts.concurrency, + () => asyncFifoQueue.numTotal() <= this._concurrency, jobsInProgress, ), this.opts.runRetryDelay, diff --git a/tests/test_worker.ts b/tests/test_worker.ts index a97c70f5b7..d8542039a9 100644 --- a/tests/test_worker.ts +++ b/tests/test_worker.ts @@ -4497,4 +4497,13 @@ describe('workers', function () { await worker.close(); }); + + it('should retrieve concurrency from getter', async () => { + const worker = new Worker(queueName, async () => {}, { connection, concurrency: 100 }); + worker.concurrency = 10; + + expect(worker.concurrency).to.equal(10); + + await worker.close(); + }); });