fix(tasktree): validate L1 lifecycle inputs
This commit is contained in:
@@ -79,6 +79,19 @@ if (action === "start") {
|
||||
console.log(JSON.stringify({ ok: true, action, status: "already-running", pid, logPath }));
|
||||
process.exit(0);
|
||||
}
|
||||
const requiredEnvironment = ["TASKTREE_NATIVE_DATABASE_ENV_FILE", "TASKTREE_TEMPORAL_ADDRESS"] as const;
|
||||
const missingEnvironment = requiredEnvironment.filter((key) => !process.env[key]?.trim());
|
||||
if (missingEnvironment.length > 0) {
|
||||
console.error(JSON.stringify({
|
||||
ok: false,
|
||||
action,
|
||||
status: "preflight-failed",
|
||||
error: "missing-required-environment",
|
||||
missingEnvironment,
|
||||
valuesPrinted: false
|
||||
}));
|
||||
process.exit(1);
|
||||
}
|
||||
rmSync(pidPath, { force: true });
|
||||
const logFd = openSync(logPath, "a");
|
||||
const child = Bun.spawn([process.execPath, "scripts/tasktree-native-supervisor.ts"], {
|
||||
@@ -91,6 +104,19 @@ if (action === "start") {
|
||||
});
|
||||
child.unref();
|
||||
await Bun.write(pidPath, `${child.pid}\n`);
|
||||
await Bun.sleep(150);
|
||||
if (!isRunning(child.pid)) {
|
||||
rmSync(pidPath, { force: true });
|
||||
console.error(JSON.stringify({
|
||||
ok: false,
|
||||
action,
|
||||
status: "start-failed",
|
||||
error: "supervisor-exited-before-ready",
|
||||
logPath,
|
||||
valuesPrinted: false
|
||||
}));
|
||||
process.exit(1);
|
||||
}
|
||||
console.log(JSON.stringify({ ok: true, action, status: "started", pid: child.pid, logPath }));
|
||||
} else if (action === "stop") {
|
||||
if (!isRunning(pid)) {
|
||||
|
||||
Reference in New Issue
Block a user