* Clean up all processes for a workspace. * Terminates running processes and removes from memory. * Output directories are left on disk (cleaned by OS for /tmp, or on workspace deletion for local).
(workspaceId: string)
| 1346 | * Output directories are left on disk (cleaned by OS for /tmp, or on workspace deletion for local). |
| 1347 | */ |
| 1348 | async cleanup(workspaceId: string): Promise<void> { |
| 1349 | log.debug(`BackgroundProcessManager.cleanup(${workspaceId}) called`); |
| 1350 | const matching = Array.from(this.processes.values()).filter( |
| 1351 | (p) => p.workspaceId === workspaceId |
| 1352 | ); |
| 1353 | |
| 1354 | // Terminate all running processes |
| 1355 | await Promise.all(matching.map((p) => this.terminate(p.id))); |
| 1356 | |
| 1357 | // Remove from memory (output dirs left on disk for OS/workspace cleanup) |
| 1358 | // All per-process state (outputBytesRead, outputLock) is stored in the |
| 1359 | // BackgroundProcess object, so cleanup is automatic when we delete here. |
| 1360 | for (const p of matching) { |
| 1361 | this.processes.delete(p.id); |
| 1362 | } |
| 1363 | |
| 1364 | log.debug(`Cleaned up ${matching.length} process(es) for workspace ${workspaceId}`); |
| 1365 | } |
| 1366 | } |