Spaces:
Running
Running
feat: implement graceful shutdown after successful configuration application
Browse files- wa-guardian.js +5 -0
wa-guardian.js
CHANGED
|
@@ -29,6 +29,7 @@ let isWaiting = false;
|
|
| 29 |
let hasShownWaitMessage = false;
|
| 30 |
let last515At = 0;
|
| 31 |
let lastConnectedAt = 0;
|
|
|
|
| 32 |
|
| 33 |
function extractErrorMessage(msg) {
|
| 34 |
if (!msg || typeof msg !== "object") return "Unknown error";
|
|
@@ -118,6 +119,7 @@ async function callRpc(ws, method, params) {
|
|
| 118 |
}
|
| 119 |
|
| 120 |
async function checkStatus() {
|
|
|
|
| 121 |
if (isWaiting) return;
|
| 122 |
if (lastConnectedAt && Date.now() - lastConnectedAt < SUCCESS_COOLDOWN_MS) return;
|
| 123 |
|
|
@@ -171,6 +173,9 @@ async function checkStatus() {
|
|
| 171 |
await callRpc(ws, "config.apply", { raw: getRes.payload.raw, baseHash: getRes.payload.hash });
|
| 172 |
console.log("[guardian] Configuration re-applied.");
|
| 173 |
}
|
|
|
|
|
|
|
|
|
|
| 174 |
} else if (!message.includes("No active") && !message.includes("Still waiting")) {
|
| 175 |
console.log(`[guardian] Wait result: ${message}`);
|
| 176 |
}
|
|
|
|
| 29 |
let hasShownWaitMessage = false;
|
| 30 |
let last515At = 0;
|
| 31 |
let lastConnectedAt = 0;
|
| 32 |
+
let shouldStop = false;
|
| 33 |
|
| 34 |
function extractErrorMessage(msg) {
|
| 35 |
if (!msg || typeof msg !== "object") return "Unknown error";
|
|
|
|
| 119 |
}
|
| 120 |
|
| 121 |
async function checkStatus() {
|
| 122 |
+
if (shouldStop) return;
|
| 123 |
if (isWaiting) return;
|
| 124 |
if (lastConnectedAt && Date.now() - lastConnectedAt < SUCCESS_COOLDOWN_MS) return;
|
| 125 |
|
|
|
|
| 173 |
await callRpc(ws, "config.apply", { raw: getRes.payload.raw, baseHash: getRes.payload.hash });
|
| 174 |
console.log("[guardian] Configuration re-applied.");
|
| 175 |
}
|
| 176 |
+
|
| 177 |
+
shouldStop = true;
|
| 178 |
+
setTimeout(() => process.exit(0), 1000);
|
| 179 |
} else if (!message.includes("No active") && !message.includes("Still waiting")) {
|
| 180 |
console.log(`[guardian] Wait result: ${message}`);
|
| 181 |
}
|