fix(web): 串行化 native CaseRun 热重载
This commit is contained in:
@@ -26,6 +26,15 @@ function isRunning(pid: number | null): boolean {
|
||||
}
|
||||
}
|
||||
|
||||
async function waitForExit(pid: number): Promise<boolean> {
|
||||
const deadline = Date.now() + 5000;
|
||||
while (Date.now() < deadline) {
|
||||
if (!isRunning(pid)) return true;
|
||||
await Bun.sleep(25);
|
||||
}
|
||||
return !isRunning(pid);
|
||||
}
|
||||
|
||||
mkdirSync(stateDir, { recursive: true });
|
||||
const pid = readPid();
|
||||
|
||||
@@ -46,8 +55,12 @@ if (action === "start") {
|
||||
console.log(JSON.stringify({ ok: true, action, status: "stopped" }));
|
||||
} else {
|
||||
process.kill(pid!, "SIGTERM");
|
||||
if (!await waitForExit(pid!)) {
|
||||
console.error(JSON.stringify({ ok: false, action, status: "stop-timeout", pid }));
|
||||
process.exit(1);
|
||||
}
|
||||
rmSync(pidPath, { force: true });
|
||||
console.log(JSON.stringify({ ok: true, action, status: "stopping", pid }));
|
||||
console.log(JSON.stringify({ ok: true, action, status: "stopped", pid }));
|
||||
}
|
||||
} else if (action === "status") {
|
||||
const running = isRunning(pid);
|
||||
|
||||
Reference in New Issue
Block a user