* Cleans up the volume. Should be called in a finally block. * * @example * ```typescript * const volume = new IsolatedContainerVolume(tenantId, runId); * try { * await volume.initialize({ 'input.txt': 'data' }); * // ... use volume ... * } finally { * await volume.c
()
| 434 | * ``` |
| 435 | */ |
| 436 | async cleanup(): Promise<void> { |
| 437 | if (!this.volumeName) { |
| 438 | return; // Nothing to clean up |
| 439 | } |
| 440 | |
| 441 | try { |
| 442 | await this.executeDockerCommand('volume', 'rm', [this.volumeName]); |
| 443 | } catch (error) { |
| 444 | // Log but don't throw - cleanup should be best-effort |
| 445 | console.error( |
| 446 | `Failed to cleanup volume ${this.volumeName}: ${error instanceof Error ? error.message : String(error)}`, |
| 447 | ); |
| 448 | } finally { |
| 449 | this.isInitialized = false; |
| 450 | this.volumeName = undefined; |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | /** |
| 455 | * Executes a docker command using spawn. |