Spaces:
Sleeping
Sleeping
feat: add graceful shutdown mechanism to stop guardian after configuration re-application
Browse files- wa-guardian.js +5 -0
wa-guardian.js
CHANGED
|
@@ -31,6 +31,7 @@ let isWaiting = false;
|
|
| 31 |
let hasShownWaitMessage = false;
|
| 32 |
let last515At = 0;
|
| 33 |
let lastConnectedAt = 0;
|
|
|
|
| 34 |
|
| 35 |
function extractErrorMessage(msg) {
|
| 36 |
if (!msg || typeof msg !== "object") return "Unknown error";
|
|
@@ -142,6 +143,7 @@ async function callRpc(ws, method, params) {
|
|
| 142 |
}
|
| 143 |
|
| 144 |
async function checkStatus() {
|
|
|
|
| 145 |
if (isWaiting) return;
|
| 146 |
if (lastConnectedAt && Date.now() - lastConnectedAt < SUCCESS_COOLDOWN_MS)
|
| 147 |
return;
|
|
@@ -205,6 +207,9 @@ async function checkStatus() {
|
|
| 205 |
});
|
| 206 |
console.log("[guardian] Configuration re-applied.");
|
| 207 |
}
|
|
|
|
|
|
|
|
|
|
| 208 |
} else if (
|
| 209 |
!message.includes("No active") &&
|
| 210 |
!message.includes("Still waiting")
|
|
|
|
| 31 |
let hasShownWaitMessage = false;
|
| 32 |
let last515At = 0;
|
| 33 |
let lastConnectedAt = 0;
|
| 34 |
+
let shouldStop = false;
|
| 35 |
|
| 36 |
function extractErrorMessage(msg) {
|
| 37 |
if (!msg || typeof msg !== "object") return "Unknown error";
|
|
|
|
| 143 |
}
|
| 144 |
|
| 145 |
async function checkStatus() {
|
| 146 |
+
if (shouldStop) return;
|
| 147 |
if (isWaiting) return;
|
| 148 |
if (lastConnectedAt && Date.now() - lastConnectedAt < SUCCESS_COOLDOWN_MS)
|
| 149 |
return;
|
|
|
|
| 207 |
});
|
| 208 |
console.log("[guardian] Configuration re-applied.");
|
| 209 |
}
|
| 210 |
+
|
| 211 |
+
shouldStop = true;
|
| 212 |
+
setTimeout(() => process.exit(0), 1000);
|
| 213 |
} else if (
|
| 214 |
!message.includes("No active") &&
|
| 215 |
!message.includes("Still waiting")
|