mirror of
https://github.com/openclaw/openclaw.git
synced 2026-02-19 18:39:20 -05:00
fix: retry gateway watch after dist rebuild
This commit is contained in:
@@ -22,11 +22,32 @@ const compilerProcess = spawn("pnpm", ["tsdown", '--watch', 'src/'], {
|
||||
stdio: "inherit",
|
||||
});
|
||||
|
||||
const nodeProcess = spawn(process.execPath, ["--watch", "openclaw.mjs", ...args], {
|
||||
cwd,
|
||||
env,
|
||||
stdio: "inherit",
|
||||
});
|
||||
let nodeProcess = null;
|
||||
let restartTimer = null;
|
||||
|
||||
function spawnNode() {
|
||||
nodeProcess = spawn(process.execPath, ["--watch", "openclaw.mjs", ...args], {
|
||||
cwd,
|
||||
env,
|
||||
stdio: "inherit",
|
||||
});
|
||||
|
||||
nodeProcess.on("exit", (code, signal) => {
|
||||
if (signal || exiting) {
|
||||
return;
|
||||
}
|
||||
// If the build is mid-refresh, node can exit on missing modules. Retry.
|
||||
if (restartTimer) {
|
||||
clearTimeout(restartTimer);
|
||||
}
|
||||
restartTimer = setTimeout(() => {
|
||||
restartTimer = null;
|
||||
spawnNode();
|
||||
}, 250);
|
||||
});
|
||||
}
|
||||
|
||||
spawnNode();
|
||||
|
||||
let exiting = false;
|
||||
|
||||
@@ -35,7 +56,11 @@ function cleanup(code = 0) {
|
||||
return;
|
||||
}
|
||||
exiting = true;
|
||||
nodeProcess.kill("SIGTERM");
|
||||
if (restartTimer) {
|
||||
clearTimeout(restartTimer);
|
||||
restartTimer = null;
|
||||
}
|
||||
nodeProcess?.kill("SIGTERM");
|
||||
compilerProcess.kill("SIGTERM");
|
||||
process.exit(code);
|
||||
}
|
||||
@@ -49,10 +74,3 @@ compilerProcess.on("exit", (code) => {
|
||||
}
|
||||
cleanup(code ?? 1);
|
||||
});
|
||||
|
||||
nodeProcess.on("exit", (code, signal) => {
|
||||
if (signal || exiting) {
|
||||
return;
|
||||
}
|
||||
cleanup(code ?? 1);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user