File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments