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