* Process any file:// references in the configuration and initialize worker pool * This should be called after initialization * @returns A promise that resolves when all file references have been processed
()
| 208 | * @returns A promise that resolves when all file references have been processed |
| 209 | */ |
| 210 | public async initialize(): Promise<void> { |
| 211 | // If already initialized, return immediately |
| 212 | if (this.isInitialized) { |
| 213 | return; |
| 214 | } |
| 215 | |
| 216 | // If initialization is in progress, return the existing promise |
| 217 | if (this.initializationPromise != null) { |
| 218 | return this.initializationPromise; |
| 219 | } |
| 220 | |
| 221 | // Start initialization and store the promise |
| 222 | this.initializationPromise = (async () => { |
| 223 | try { |
| 224 | this.config = await processConfigFileReferences( |
| 225 | this.config, |
| 226 | this.options?.config.basePath || '', |
| 227 | ); |
| 228 | |
| 229 | // Initialize worker pool |
| 230 | const workerCount = this.getWorkerCount(); |
| 231 | const absPath = path.resolve( |
| 232 | path.join(this.options?.config.basePath || '', this.scriptPath), |
| 233 | ); |
| 234 | |
| 235 | this.pool = new PythonWorkerPool( |
| 236 | absPath, |
| 237 | this.functionName || 'call_api', |
| 238 | workerCount, |
| 239 | getConfiguredPythonPath(this.config.pythonExecutable), |
| 240 | this.config.timeout, |
| 241 | ); |
| 242 | |
| 243 | await this.pool.initialize(); |
| 244 | |
| 245 | // Register for cleanup |
| 246 | providerRegistry.register(this); |
| 247 | |
| 248 | this.isInitialized = true; |
| 249 | logger.debug(`Initialized Python provider ${this.id()} with ${workerCount} workers`); |
| 250 | } catch (error) { |
| 251 | // Reset the initialization promise so future calls can retry |
| 252 | this.initializationPromise = null; |
| 253 | throw error; |
| 254 | } |
| 255 | })(); |
| 256 | |
| 257 | return this.initializationPromise; |
| 258 | } |
| 259 | |
| 260 | /** |
| 261 | * Determine worker count based on config and environment |
no test coverage detected