@@ -2,22 +2,12 @@ import { Execution, ExecutionOptions } from './Execution'
22import { PubSub } from '@/lib/pubsub'
33import { Logging } from '@/lib/utils/Logging'
44
5- // Default execution ID for backwards compatibility
6- const DEFAULT_EXECUTION_ID = 'default'
7-
8- // Maximum concurrent executions allowed
9- const MAX_CONCURRENT_EXECUTIONS = 10
10-
11- // Execution cleanup timeout (30 minutes)
12- const EXECUTION_CLEANUP_TIMEOUT = 30 * 60 * 1000
13-
145/**
156 * Manages all active execution instances.
167 * Handles creation, retrieval, and lifecycle management.
178 */
189export class ExecutionManager {
1910 private executions : Map < string , Execution > = new Map ( )
20- private cleanupTimers : Map < string , NodeJS . Timeout > = new Map ( )
2111 private static instance : ExecutionManager | null = null
2212
2313 constructor ( ) {
@@ -47,16 +37,6 @@ export class ExecutionManager {
4737 throw new Error ( `Execution ${ executionId } already exists` )
4838 }
4939
50- // Check maximum concurrent executions
51- if ( this . executions . size >= MAX_CONCURRENT_EXECUTIONS ) {
52- // Try to clean up completed executions first
53- this . _cleanupCompletedExecutions ( )
54-
55- if ( this . executions . size >= MAX_CONCURRENT_EXECUTIONS ) {
56- throw new Error ( `Maximum concurrent executions (${ MAX_CONCURRENT_EXECUTIONS } ) reached` )
57- }
58- }
59-
6040 // Get or create PubSub channel for this execution
6141 const pubsub = PubSub . getChannel ( executionId )
6242
@@ -69,9 +49,6 @@ export class ExecutionManager {
6949 const execution = new Execution ( fullOptions , pubsub )
7050 this . executions . set ( executionId , execution )
7151
72- // Clear any existing cleanup timer
73- this . _clearCleanupTimer ( executionId )
74-
7552 Logging . log ( 'ExecutionManager' , `Created execution ${ executionId } (total: ${ this . executions . size } )` )
7653
7754 return execution
@@ -89,23 +66,16 @@ export class ExecutionManager {
8966 /**
9067 * Delete an execution instance
9168 * @param executionId - Execution identifier to delete
92- * @param immediate - If true, dispose immediately without cleanup timer
9369 */
94- async delete ( executionId : string , immediate : boolean = false ) : Promise < void > {
70+ async delete ( executionId : string ) : Promise < void > {
9571 const execution = this . executions . get ( executionId )
9672
9773 if ( ! execution ) {
9874 Logging . log ( 'ExecutionManager' , `Execution ${ executionId } not found for deletion` )
9975 return
10076 }
10177
102- if ( immediate ) {
103- // Immediate disposal
104- await this . _disposeExecution ( executionId )
105- } else {
106- // Schedule cleanup after timeout (allows for reconnection)
107- this . _scheduleCleanup ( executionId )
108- }
78+ await this . _disposeExecution ( executionId )
10979 }
11080
11181 /**
@@ -181,12 +151,6 @@ export class ExecutionManager {
181151 * Dispose all executions and cleanup
182152 */
183153 async disposeAll ( ) : Promise < void > {
184- // Cancel all cleanup timers
185- for ( const timer of this . cleanupTimers . values ( ) ) {
186- clearTimeout ( timer )
187- }
188- this . cleanupTimers . clear ( )
189-
190154 // Dispose all executions
191155 const disposalPromises = [ ]
192156 for ( const executionId of this . executions . keys ( ) ) {
@@ -219,66 +183,8 @@ export class ExecutionManager {
219183 // Delete PubSub channel
220184 PubSub . deleteChannel ( executionId )
221185
222- // Clear cleanup timer
223- this . _clearCleanupTimer ( executionId )
224-
225186 Logging . log ( 'ExecutionManager' , `Disposed execution ${ executionId } (remaining: ${ this . executions . size } )` )
226187 }
227188
228- /**
229- * Schedule cleanup of an execution after timeout
230- * @private
231- */
232- private _scheduleCleanup ( executionId : string ) : void {
233- // Clear any existing timer
234- this . _clearCleanupTimer ( executionId )
235-
236- // Schedule new cleanup
237- const timer = setTimeout ( async ( ) => {
238- Logging . log ( 'ExecutionManager' , `Auto-cleanup triggered for execution ${ executionId } ` )
239- await this . _disposeExecution ( executionId )
240- } , EXECUTION_CLEANUP_TIMEOUT )
241-
242- this . cleanupTimers . set ( executionId , timer )
243-
244- Logging . log ( 'ExecutionManager' , `Scheduled cleanup for execution ${ executionId } in ${ EXECUTION_CLEANUP_TIMEOUT } ms` )
245- }
246189
247- /**
248- * Clear cleanup timer for an execution
249- * @private
250- */
251- private _clearCleanupTimer ( executionId : string ) : void {
252- const timer = this . cleanupTimers . get ( executionId )
253- if ( timer ) {
254- clearTimeout ( timer )
255- this . cleanupTimers . delete ( executionId )
256- }
257- }
258-
259- /**
260- * Clean up completed executions to free resources
261- * @private
262- */
263- private _cleanupCompletedExecutions ( ) : void {
264- const toCleanup : string [ ] = [ ]
265-
266- // For now, we can only clean up executions that are not running
267- // In the future we might track completion time
268- for ( const [ id , execution ] of this . executions ) {
269- if ( ! execution . isRunning ( ) ) {
270- toCleanup . push ( id )
271- }
272- }
273-
274- for ( const id of toCleanup ) {
275- this . _disposeExecution ( id ) . catch ( error => {
276- Logging . log ( 'ExecutionManager' , `Error cleaning up execution ${ id } : ${ error } ` , 'error' )
277- } )
278- }
279-
280- if ( toCleanup . length > 0 ) {
281- Logging . log ( 'ExecutionManager' , `Cleaned up ${ toCleanup . length } completed executions` )
282- }
283- }
284190}
0 commit comments