@meyverick/omnicode 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/bin/omnicode-runtime.js +14 -3
package/package.json
CHANGED
|
@@ -21,15 +21,17 @@ async function initTool(name, args, logPath) {
|
|
|
21
21
|
try {
|
|
22
22
|
log = openSync(logPath, "w");
|
|
23
23
|
const child = spawn(name, args, { stdio: ["ignore", log, log] });
|
|
24
|
+
let timer;
|
|
24
25
|
const result = await Promise.race([
|
|
25
26
|
new Promise((resolve) => {
|
|
26
27
|
child.on("close", resolve);
|
|
27
28
|
child.on("error", () => resolve(null));
|
|
28
29
|
}),
|
|
29
30
|
new Promise((resolve) => {
|
|
30
|
-
setTimeout(() => { child.kill(); resolve(null); }, 30000);
|
|
31
|
+
timer = setTimeout(() => { child.kill(); resolve(null); }, 30000);
|
|
31
32
|
}),
|
|
32
33
|
]);
|
|
34
|
+
clearTimeout(timer);
|
|
33
35
|
if (result === null) {
|
|
34
36
|
console.log(`[omnicode] WARNING: ${name} init timed out; continuing. Log: ${logPath}`);
|
|
35
37
|
} else if (result === 0) {
|
|
@@ -123,7 +125,7 @@ async function stopOmnirouteIfIdle(pidFile) {
|
|
|
123
125
|
}
|
|
124
126
|
for (let i = 0; i < 10; i++) {
|
|
125
127
|
if (!isPidAlive(pid)) break;
|
|
126
|
-
|
|
128
|
+
await sleep(100);
|
|
127
129
|
}
|
|
128
130
|
}
|
|
129
131
|
try { unlinkSync(pidFile); } catch {}
|
|
@@ -142,7 +144,16 @@ export async function runRuntime(mode) {
|
|
|
142
144
|
}
|
|
143
145
|
|
|
144
146
|
const cleanup = async () => { await stopOmnirouteIfIdle(pidFile); };
|
|
145
|
-
process.on("exit", () => {
|
|
147
|
+
process.on("exit", () => {
|
|
148
|
+
try {
|
|
149
|
+
if (!existsSync(pidFile)) return;
|
|
150
|
+
const pid = parseInt(readFileSync(pidFile, "utf8").trim(), 10);
|
|
151
|
+
if (pid && isPidAlive(pid)) {
|
|
152
|
+
process.kill(-pid, "SIGTERM");
|
|
153
|
+
}
|
|
154
|
+
unlinkSync(pidFile);
|
|
155
|
+
} catch {}
|
|
156
|
+
});
|
|
146
157
|
process.on("SIGINT", async () => { await cleanup(); process.exit(0); });
|
|
147
158
|
process.on("SIGTERM", async () => { await cleanup(); process.exit(0); });
|
|
148
159
|
|