Skip to content

Commit 2a1cdbe

Browse files
committed
fix(worker): throw error with invalid concurrency fixes #1723
1 parent 4cb5250 commit 2a1cdbe

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/classes/worker.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ export class Worker<
219219
...this.opts,
220220
};
221221

222+
this.concurrency = this.opts.concurrency;
223+
222224
this.opts.lockRenewTime =
223225
this.opts.lockRenewTime || this.opts.lockDuration / 2;
224226

@@ -339,6 +341,9 @@ export class Worker<
339341
}
340342

341343
set concurrency(concurrency: number) {
344+
if (typeof concurrency !== 'number' || concurrency < 1) {
345+
throw new Error('concurrency must be a number greater than 0');
346+
}
342347
this.opts.concurrency = concurrency;
343348
}
344349

tests/test_worker.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1587,6 +1587,20 @@ describe('workers', function () {
15871587
});
15881588

15891589
describe('Concurrency process', () => {
1590+
it('should thrown an exception if I specify a concurrency of 0', () => {
1591+
try {
1592+
const worker = new Worker(queueName, async () => {}, {
1593+
connection,
1594+
concurrency: 0,
1595+
});
1596+
throw new Error('Should have thrown an exception');
1597+
} catch (err) {
1598+
expect(err.message).to.be.equal(
1599+
'concurrency must be a number greater than 0',
1600+
);
1601+
}
1602+
});
1603+
15901604
it('should run job in sequence if I specify a concurrency of 1', async () => {
15911605
let processing = false;
15921606

0 commit comments

Comments
 (0)