@@ -21,7 +21,6 @@ import {
21
21
DELAY_TIME_1 ,
22
22
isNotConnectionError ,
23
23
isRedisInstance ,
24
- WORKER_SUFFIX ,
25
24
} from '../utils' ;
26
25
import { QueueBase } from './queue-base' ;
27
26
import { Repeat } from './repeat' ;
@@ -256,16 +255,21 @@ export class Worker<
256
255
}
257
256
}
258
257
259
- const mainFile = this . opts . useWorkerThreads
260
- ? 'main-worker.js'
261
- : 'main.js' ;
262
- let mainFilePath = path . join (
263
- path . dirname ( module . filename ) ,
264
- `${ mainFile } ` ,
265
- ) ;
258
+ // Separate paths so that bundling tools can resolve dependencies easier
259
+ const dirname = path . dirname ( module . filename || __filename ) ;
260
+ const workerThreadsMainFile = path . join ( dirname , 'main-worker.js' ) ;
261
+ const spawnProcessMainFile = path . join ( dirname , 'main.js' ) ;
262
+
263
+ let mainFilePath = this . opts . useWorkerThreads
264
+ ? workerThreadsMainFile
265
+ : spawnProcessMainFile ;
266
+
266
267
try {
267
268
fs . statSync ( mainFilePath ) ; // would throw if file not exists
268
269
} catch ( _ ) {
270
+ const mainFile = this . opts . useWorkerThreads
271
+ ? 'main-worker.js'
272
+ : 'main.js' ;
269
273
mainFilePath = path . join (
270
274
process . cwd ( ) ,
271
275
`dist/cjs/classes/${ mainFile } ` ,
@@ -289,7 +293,8 @@ export class Worker<
289
293
}
290
294
}
291
295
292
- const connectionName = this . clientName ( WORKER_SUFFIX ) ;
296
+ const connectionName =
297
+ this . clientName ( ) + ( this . opts . name ? `:w:${ this . opts . name } ` : '' ) ;
293
298
this . blockingConnection = new RedisConnection (
294
299
isRedisInstance ( opts . connection )
295
300
? ( < Redis > opts . connection ) . duplicate ( { connectionName } )
@@ -530,7 +535,7 @@ export class Worker<
530
535
this . blockUntil = await this . waiting ;
531
536
532
537
if ( this . blockUntil <= 0 || this . blockUntil - Date . now ( ) < 10 ) {
533
- return this . moveToActive ( client , token ) ;
538
+ return this . moveToActive ( client , token , this . opts . name ) ;
534
539
}
535
540
} catch ( err ) {
536
541
// Swallow error if locally paused or closing since we did force a disconnection
@@ -549,7 +554,7 @@ export class Worker<
549
554
this . abortDelayController = new AbortController ( ) ;
550
555
await this . delay ( this . limitUntil , this . abortDelayController ) ;
551
556
}
552
- return this . moveToActive ( client , token ) ;
557
+ return this . moveToActive ( client , token , this . opts . name ) ;
553
558
}
554
559
}
555
560
@@ -572,9 +577,10 @@ export class Worker<
572
577
protected async moveToActive (
573
578
client : RedisClient ,
574
579
token : string ,
580
+ name ?: string ,
575
581
) : Promise < Job < DataType , ResultType , NameType > > {
576
582
const [ jobData , id , limitUntil , delayUntil ] =
577
- await this . scripts . moveToActive ( client , token ) ;
583
+ await this . scripts . moveToActive ( client , token , name ) ;
578
584
this . updateDelays ( limitUntil , delayUntil ) ;
579
585
580
586
return this . nextJobFromJobData ( jobData , id , token ) ;
0 commit comments