@@ -43,6 +43,11 @@ export type FairDequeuingStrategyOptions = {
43
43
biases ?: FairDequeuingStrategyBiases ;
44
44
reuseSnapshotCount ?: number ;
45
45
maximumEnvCount ?: number ;
46
+ /**
47
+ * Maximum number of queues to process per environment
48
+ * If not provided, all queues in an environment will be processed
49
+ */
50
+ maximumQueuePerEnvCount ?: number ;
46
51
} ;
47
52
48
53
type FairQueueConcurrency = {
@@ -216,8 +221,6 @@ export class FairDequeuingStrategy implements MarQSFairDequeueStrategy {
216
221
return result ;
217
222
}
218
223
219
- // Helper method to maintain DRY principle
220
- // Update return type
221
224
#orderQueuesByEnvs( envs : string [ ] , snapshot : FairQueueSnapshot ) : Array < EnvQueues > {
222
225
const queuesByEnv = snapshot . queues . reduce ( ( acc , queue ) => {
223
226
if ( ! acc [ queue . env ] ) {
@@ -231,11 +234,17 @@ export class FairDequeuingStrategy implements MarQSFairDequeueStrategy {
231
234
if ( queuesByEnv [ envId ] ) {
232
235
// Get ordered queues for this env
233
236
const orderedQueues = this . #weightedRandomQueueOrder( queuesByEnv [ envId ] ) ;
237
+
238
+ // Apply queue limit if maximumQueuePerEnvCount is set
239
+ const limitedQueues = this . options . maximumQueuePerEnvCount
240
+ ? orderedQueues . slice ( 0 , this . options . maximumQueuePerEnvCount )
241
+ : orderedQueues ;
242
+
234
243
// Only add the env if it has queues
235
- if ( orderedQueues . length > 0 ) {
244
+ if ( limitedQueues . length > 0 ) {
236
245
acc . push ( {
237
246
envId,
238
- queues : orderedQueues . map ( ( queue ) => queue . id ) ,
247
+ queues : limitedQueues . map ( ( queue ) => queue . id ) ,
239
248
} ) ;
240
249
}
241
250
}
@@ -512,6 +521,10 @@ export class FairDequeuingStrategy implements MarQSFairDequeueStrategy {
512
521
513
522
span . setAttribute ( "queue_count" , result . length ) ;
514
523
524
+ if ( result . length === this . options . parentQueueLimit ) {
525
+ span . setAttribute ( "parent_queue_limit_reached" , true ) ;
526
+ }
527
+
515
528
return result ;
516
529
} ) ;
517
530
}
0 commit comments