@@ -18,6 +18,7 @@ type SupervisorSessionOptions = SupervisorClientCommonOptions & {
18
18
preDequeue ?: PreDequeueFn ;
19
19
preSkip ?: PreSkipFn ;
20
20
maxRunCount ?: number ;
21
+ maxConsumerCount ?: number ;
21
22
} ;
22
23
23
24
export class SupervisorSession extends EventEmitter < WorkerEvents > {
@@ -27,7 +28,7 @@ export class SupervisorSession extends EventEmitter<WorkerEvents> {
27
28
private runNotificationsSocket ?: Socket < WorkerServerToClientEvents , WorkerClientToServerEvents > ;
28
29
29
30
private readonly queueConsumerEnabled : boolean ;
30
- private readonly queueConsumer : RunQueueConsumer ;
31
+ private readonly queueConsumers : RunQueueConsumer [ ] ;
31
32
32
33
private readonly heartbeat : IntervalService ;
33
34
private readonly heartbeatIntervalSeconds : number ;
@@ -39,13 +40,15 @@ export class SupervisorSession extends EventEmitter<WorkerEvents> {
39
40
this . queueConsumerEnabled = opts . queueConsumerEnabled ?? true ;
40
41
41
42
this . httpClient = new SupervisorHttpClient ( opts ) ;
42
- this . queueConsumer = new RunQueueConsumer ( {
43
- client : this . httpClient ,
44
- preDequeue : opts . preDequeue ,
45
- preSkip : opts . preSkip ,
46
- onDequeue : this . onDequeue . bind ( this ) ,
47
- intervalMs : opts . dequeueIntervalMs ,
48
- maxRunCount : opts . maxRunCount ,
43
+ this . queueConsumers = Array . from ( { length : opts . maxConsumerCount ?? 1 } , ( ) => {
44
+ return new RunQueueConsumer ( {
45
+ client : this . httpClient ,
46
+ preDequeue : opts . preDequeue ,
47
+ preSkip : opts . preSkip ,
48
+ onDequeue : this . onDequeue . bind ( this ) ,
49
+ intervalMs : opts . dequeueIntervalMs ,
50
+ maxRunCount : opts . maxRunCount ,
51
+ } ) ;
49
52
} ) ;
50
53
51
54
// TODO: This should be dynamic and set by (or at least overridden by) the platform
@@ -181,7 +184,7 @@ export class SupervisorSession extends EventEmitter<WorkerEvents> {
181
184
182
185
if ( this . queueConsumerEnabled ) {
183
186
console . log ( "[SupervisorSession] Queue consumer enabled" ) ;
184
- this . queueConsumer . start ( ) ;
187
+ await Promise . allSettled ( this . queueConsumers . map ( async ( q ) => q . start ( ) ) ) ;
185
188
this . heartbeat . start ( ) ;
186
189
} else {
187
190
console . warn ( "[SupervisorSession] Queue consumer disabled" ) ;
@@ -196,6 +199,7 @@ export class SupervisorSession extends EventEmitter<WorkerEvents> {
196
199
}
197
200
198
201
async stop ( ) {
202
+ await Promise . allSettled ( this . queueConsumers . map ( async ( q ) => q . stop ( ) ) ) ;
199
203
this . heartbeat . stop ( ) ;
200
204
this . runNotificationsSocket ?. disconnect ( ) ;
201
205
}
0 commit comments