( execStream: ExecStream, options: MigrateOptions, bgOutputDir: string )
| 379 | * @param bgOutputDir Base directory for output files |
| 380 | */ |
| 381 | export async function migrateToBackground( |
| 382 | execStream: ExecStream, |
| 383 | options: MigrateOptions, |
| 384 | bgOutputDir: string |
| 385 | ): Promise<MigrateResult> { |
| 386 | // Use shared path computation (path.join for local filesystem) |
| 387 | const { outputDir, outputPath } = computeOutputPaths( |
| 388 | bgOutputDir, |
| 389 | options.workspaceId, |
| 390 | options.processId |
| 391 | ); |
| 392 | |
| 393 | try { |
| 394 | // Create output directory |
| 395 | await fs.mkdir(outputDir, { recursive: true }); |
| 396 | |
| 397 | // Write existing output to unified output.log |
| 398 | await fs.writeFile(outputPath, options.existingOutput.join("\n") + "\n"); |
| 399 | |
| 400 | // Create handle that will continue writing to file |
| 401 | const handle = new MigratedBackgroundHandle(execStream, outputDir, outputPath); |
| 402 | |
| 403 | // Start consuming remaining output in background |
| 404 | handle.startConsuming(); |
| 405 | |
| 406 | return { success: true, handle, outputDir }; |
| 407 | } catch (error) { |
| 408 | const errorMessage = errorMsg(error); |
| 409 | log.debug(`migrateToBackground: Error: ${errorMessage}`); |
| 410 | return { success: false, error: `Failed to migrate process: ${errorMessage}` }; |
| 411 | } |
| 412 | } |
| 413 | |
| 414 | /** |
| 415 | * Handle for a migrated foreground process. |
no test coverage detected