@@ -35,7 +35,6 @@ import {
3535} from "./errors.js" ;
3636import { EventBus , EventBusEvents } from "./eventBus.js" ;
3737import { RunLocker } from "./locking.js" ;
38- import { ReleaseConcurrencyTokenBucketQueue } from "./releaseConcurrencyTokenBucketQueue.js" ;
3938import { BatchSystem } from "./systems/batchSystem.js" ;
4039import { CheckpointSystem } from "./systems/checkpointSystem.js" ;
4140import { DelayedRunSystem } from "./systems/delayedRunSystem.js" ;
@@ -63,11 +62,6 @@ export class RunEngine {
6362 private logger = new Logger ( "RunEngine" , "debug" ) ;
6463 private tracer : Tracer ;
6564 private heartbeatTimeouts : HeartbeatTimeouts ;
66- releaseConcurrencyQueue : ReleaseConcurrencyTokenBucketQueue < {
67- orgId : string ;
68- projectId : string ;
69- envId : string ;
70- } > ;
7165 eventBus : EventBus = new EventEmitter < EventBusEvents > ( ) ;
7266 executionSnapshotSystem : ExecutionSnapshotSystem ;
7367 runAttemptSystem : RunAttemptSystem ;
@@ -184,51 +178,6 @@ export class RunEngine {
184178 ...( options . heartbeatTimeoutsMs ?? { } ) ,
185179 } ;
186180
187- // Initialize the ReleaseConcurrencyQueue
188- this . releaseConcurrencyQueue = new ReleaseConcurrencyTokenBucketQueue ( {
189- redis : {
190- ...options . queue . redis , // Use base queue redis options
191- ...options . releaseConcurrency ?. redis , // Allow overrides
192- keyPrefix : `${ options . queue . redis . keyPrefix ?? "" } release-concurrency:` ,
193- } ,
194- retry : {
195- maxRetries : options . releaseConcurrency ?. maxRetries ?? 5 ,
196- backoff : {
197- minDelay : options . releaseConcurrency ?. backoff ?. minDelay ?? 1000 ,
198- maxDelay : options . releaseConcurrency ?. backoff ?. maxDelay ?? 10000 ,
199- factor : options . releaseConcurrency ?. backoff ?. factor ?? 2 ,
200- } ,
201- } ,
202- consumersCount : options . releaseConcurrency ?. consumersCount ?? 1 ,
203- pollInterval : options . releaseConcurrency ?. pollInterval ?? 1000 ,
204- batchSize : options . releaseConcurrency ?. batchSize ?? 10 ,
205- executor : async ( descriptor , snapshotId ) => {
206- await this . releaseConcurrencySystem . executeReleaseConcurrencyForSnapshot ( snapshotId ) ;
207- } ,
208- maxTokens : async ( descriptor ) => {
209- const environment = await this . prisma . runtimeEnvironment . findFirstOrThrow ( {
210- where : { id : descriptor . envId } ,
211- select : {
212- maximumConcurrencyLimit : true ,
213- } ,
214- } ) ;
215-
216- return (
217- environment . maximumConcurrencyLimit * ( options . releaseConcurrency ?. maxTokensRatio ?? 1.0 )
218- ) ;
219- } ,
220- keys : {
221- fromDescriptor : ( descriptor ) =>
222- `org:${ descriptor . orgId } :proj:${ descriptor . projectId } :env:${ descriptor . envId } ` ,
223- toDescriptor : ( name ) => ( {
224- orgId : name . split ( ":" ) [ 1 ] ,
225- projectId : name . split ( ":" ) [ 3 ] ,
226- envId : name . split ( ":" ) [ 5 ] ,
227- } ) ,
228- } ,
229- tracer : this . tracer ,
230- } ) ;
231-
232181 const resources : SystemResources = {
233182 prisma : this . prisma ,
234183 worker : this . worker ,
@@ -237,11 +186,60 @@ export class RunEngine {
237186 tracer : this . tracer ,
238187 runLock : this . runLock ,
239188 runQueue : this . runQueue ,
240- releaseConcurrencyQueue : this . releaseConcurrencyQueue ,
241189 } ;
242190
243191 this . releaseConcurrencySystem = new ReleaseConcurrencySystem ( {
244192 resources,
193+ queueOptions :
194+ typeof options . releaseConcurrency ?. disabled === "boolean" &&
195+ options . releaseConcurrency . disabled
196+ ? undefined
197+ : {
198+ redis : {
199+ ...options . queue . redis , // Use base queue redis options
200+ ...options . releaseConcurrency ?. redis , // Allow overrides
201+ keyPrefix : `${ options . queue . redis . keyPrefix ?? "" } release-concurrency:` ,
202+ } ,
203+ retry : {
204+ maxRetries : options . releaseConcurrency ?. maxRetries ?? 5 ,
205+ backoff : {
206+ minDelay : options . releaseConcurrency ?. backoff ?. minDelay ?? 1000 ,
207+ maxDelay : options . releaseConcurrency ?. backoff ?. maxDelay ?? 10000 ,
208+ factor : options . releaseConcurrency ?. backoff ?. factor ?? 2 ,
209+ } ,
210+ } ,
211+ consumersCount : options . releaseConcurrency ?. consumersCount ?? 1 ,
212+ pollInterval : options . releaseConcurrency ?. pollInterval ?? 1000 ,
213+ batchSize : options . releaseConcurrency ?. batchSize ?? 10 ,
214+ executor : async ( descriptor , snapshotId ) => {
215+ await this . releaseConcurrencySystem . executeReleaseConcurrencyForSnapshot (
216+ snapshotId
217+ ) ;
218+ } ,
219+ maxTokens : async ( descriptor ) => {
220+ const environment = await this . prisma . runtimeEnvironment . findFirstOrThrow ( {
221+ where : { id : descriptor . envId } ,
222+ select : {
223+ maximumConcurrencyLimit : true ,
224+ } ,
225+ } ) ;
226+
227+ return (
228+ environment . maximumConcurrencyLimit *
229+ ( options . releaseConcurrency ?. maxTokensRatio ?? 1.0 )
230+ ) ;
231+ } ,
232+ keys : {
233+ fromDescriptor : ( descriptor ) =>
234+ `org:${ descriptor . orgId } :proj:${ descriptor . projectId } :env:${ descriptor . envId } ` ,
235+ toDescriptor : ( name ) => ( {
236+ orgId : name . split ( ":" ) [ 1 ] ,
237+ projectId : name . split ( ":" ) [ 3 ] ,
238+ envId : name . split ( ":" ) [ 5 ] ,
239+ } ) ,
240+ } ,
241+ tracer : this . tracer ,
242+ } ,
245243 } ) ;
246244
247245 this . executionSnapshotSystem = new ExecutionSnapshotSystem ( {
@@ -1213,7 +1211,7 @@ export class RunEngine {
12131211 async quit ( ) {
12141212 try {
12151213 //stop the run queue
1216- await this . releaseConcurrencyQueue . quit ( ) ;
1214+ await this . releaseConcurrencySystem . quit ( ) ;
12171215 await this . runQueue . quit ( ) ;
12181216 await this . worker . stop ( ) ;
12191217 await this . runLock . quit ( ) ;
0 commit comments