(taskId: string, setAppState: SetAppStateFn)
| 14 | type SetAppStateFn = (updater: (prev: AppState) => AppState) => void |
| 15 | |
| 16 | export function killTask(taskId: string, setAppState: SetAppStateFn): void { |
| 17 | updateTaskState(taskId, setAppState, task => { |
| 18 | if ((task as any).status !== 'running' || !isLocalShellTask(task)) { |
| 19 | return task |
| 20 | } |
| 21 | |
| 22 | try { |
| 23 | logForDebugging(`LocalShellTask ${taskId} kill requested`) |
| 24 | task.shellCommand?.kill() |
| 25 | task.shellCommand?.cleanup() |
| 26 | } catch (error) { |
| 27 | logError(error) |
| 28 | } |
| 29 | |
| 30 | task.unregisterCleanup?.() |
| 31 | if (task.cleanupTimeoutId) { |
| 32 | clearTimeout(task.cleanupTimeoutId) |
| 33 | } |
| 34 | |
| 35 | return { |
| 36 | ...task, |
| 37 | status: 'killed', |
| 38 | notified: true, |
| 39 | shellCommand: null, |
| 40 | unregisterCleanup: undefined, |
| 41 | cleanupTimeoutId: undefined, |
| 42 | endTime: Date.now(), |
| 43 | } |
| 44 | }) |
| 45 | void evictTaskOutput(taskId) |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Kill all running bash tasks spawned by a given agent. |
no test coverage detected