fix(web): 串行化 native CaseRun 热重载

This commit is contained in:
root
2026-07-17 04:06:59 +02:00
parent c5ee759250
commit ee09dabfeb
4 changed files with 184 additions and 19 deletions
@@ -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);