@@ -63,22 +63,17 @@ type ExportsManagerEvents = {
6363} ;
6464
6565export class ExportsManager extends EventEmitter < ExportsManagerEvents > {
66+ private wasInitialized : boolean = false ;
6667 private storedExports : Record < StoredExport [ "exportName" ] , StoredExport > = { } ;
6768 private exportsCleanupInProgress : boolean = false ;
68- private exportsCleanupInterval : NodeJS . Timeout ;
69- private exportsDirectoryPath : string ;
69+ private exportsCleanupInterval ?: NodeJS . Timeout ;
7070
71- constructor (
72- sessionId : string ,
71+ private constructor (
72+ private readonly exportsDirectoryPath : string ,
7373 private readonly config : ExportsManagerConfig ,
7474 private readonly logger : LoggerBase
7575 ) {
7676 super ( ) ;
77- this . exportsDirectoryPath = path . join ( this . config . exportsPath , sessionId ) ;
78- this . exportsCleanupInterval = setInterval (
79- ( ) => void this . cleanupExpiredExports ( ) ,
80- this . config . exportCleanupIntervalMs
81- ) ;
8277 }
8378
8479 public get availableExports ( ) : AvailableExport [ ] {
@@ -96,6 +91,17 @@ export class ExportsManager extends EventEmitter<ExportsManagerEvents> {
9691 } ) ) ;
9792 }
9893
94+ protected init ( ) : void {
95+ if ( ! this . wasInitialized ) {
96+ this . exportsCleanupInterval = setInterval (
97+ ( ) => void this . cleanupExpiredExports ( ) ,
98+ this . config . exportCleanupIntervalMs
99+ ) ;
100+
101+ this . wasInitialized = true ;
102+ }
103+ }
104+
99105 public async close ( ) : Promise < void > {
100106 try {
101107 clearInterval ( this . exportsCleanupInterval ) ;
@@ -302,6 +308,13 @@ export class ExportsManager extends EventEmitter<ExportsManagerEvents> {
302308 }
303309 }
304310 }
311+
312+ static init ( sessionId : string , config : ExportsManagerConfig , logger : LoggerBase ) : ExportsManager {
313+ const exportsDirectoryPath = path . join ( config . exportsPath , sessionId ) ;
314+ const exportsManager = new ExportsManager ( exportsDirectoryPath , config , logger ) ;
315+ exportsManager . init ( ) ;
316+ return exportsManager ;
317+ }
305318}
306319
307320/**
0 commit comments