enables process-control to try stopping codex with sigterm when sigint fails to stop it.

This commit is contained in:
thatben 2025-04-21 13:05:03 +02:00
parent df9569314f
commit 79ca49b516
No known key found for this signature in database
GPG Key ID: 62C543548433D43E
3 changed files with 22 additions and 1 deletions

View File

@ -47,6 +47,7 @@ export const mockOsService = {
getWorkingDir: vi.fn(),
listProcesses: vi.fn(),
stopProcess: vi.fn(),
terminateProcess: vi.fn(),
};
export const mockCodexGlobals = {

View File

@ -25,9 +25,25 @@ export class ProcessControl {
if (processes.length < 1) throw new Error("No codex process found");
const pid = processes[0].pid;
await this.stopProcess(pid);
};
stopProcess = async (pid) => {
this.os.stopProcess(pid);
await this.sleep();
};
if (await this.isProcessRunning(pid)) {
this.os.terminateProcess(pid);
await this.sleep();
}
}
isProcessRunning = async (pid) => {
const processes = await this.os.listProcesses();
const p = processes.filter((p) => p.pid == pid);
const result = p.length > 0;
return result;
}
startCodexProcess = async () => {
await this.saveCodexConfigFile();

View File

@ -29,4 +29,8 @@ export class OsService {
stopProcess = (pid) => {
process.kill(pid, "SIGINT");
};
terminateProcess = (pid) => {
process.kill(pid, "SIGTERM");
}
}