chore: add proper-lockfile for safe database read/write operations and implement retry logic for file access

This commit is contained in:
decolua
2026-03-27 10:31:35 +07:00
parent 3059df4014
commit 8759545260
15 changed files with 648 additions and 57 deletions
+35
View File
@@ -0,0 +1,35 @@
// 9remote process lifecycle manager
let remoteProcess = null;
export function setRemoteProcess(child) {
remoteProcess = child;
}
export function getRemoteProcess() {
return remoteProcess;
}
export function killRemote() {
if (!remoteProcess) return;
try {
remoteProcess.kill("SIGTERM");
console.log(`[9remote] Killed process ${remoteProcess.pid}`);
remoteProcess = null;
} catch (err) {
console.log(`[9remote] Failed to kill:`, err.message);
remoteProcess = null;
}
}
// Register cleanup handlers
if (typeof process !== "undefined") {
const cleanup = () => {
killRemote();
process.exit(0);
};
process.on("SIGTERM", cleanup);
process.on("SIGINT", cleanup);
process.on("beforeExit", killRemote);
}