mslxdff 0.1.18 → 0.1.20
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/bin/mslxdff.js +40 -25
- package/package.json +1 -1
package/bin/mslxdff.js
CHANGED
|
@@ -20,6 +20,7 @@ const logs = { appendCall, appendError, appendEvent };
|
|
|
20
20
|
|
|
21
21
|
const args = process.argv.slice(2);
|
|
22
22
|
const VERSION = JSON.parse(readFileSync(join(dirname(fileURLToPath(import.meta.url)), "..", "package.json"), "utf8")).version;
|
|
23
|
+
const HEALTH_TIMEOUT_MS = 4000;
|
|
23
24
|
|
|
24
25
|
if (args.includes("-help") || args.includes("--help") || args.includes("-h")) {
|
|
25
26
|
printHelp();
|
|
@@ -195,33 +196,48 @@ if (groupCmd && groupCmd !== "create") {
|
|
|
195
196
|
const removed = peers.removeByGroup(a);
|
|
196
197
|
console.log(before ? `left group "${a}" (${removed} member(s) removed)` : `not a member of group "${a}"`);
|
|
197
198
|
} else if (action === "list") {
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
if (names.length) {
|
|
201
|
-
for (const n of names) {
|
|
202
|
-
console.log(`${n} (${Object.keys(all[n].members || {}).length} members)`);
|
|
203
|
-
// probe every member endpoint concurrently to show reachability + latency
|
|
204
|
-
const probes = Object.entries(all[n].members || {}).map(([id, m]) => ({
|
|
205
|
-
id, url: m?.url,
|
|
206
|
-
}));
|
|
207
|
-
const joined = loadGroupsJoined().find((g) => g.name === n);
|
|
208
|
-
if (joined?.leaderUrl) probes.push({ id: "leader", url: joined.leaderUrl });
|
|
209
|
-
const results = await Promise.all(probes.map(probeHealth));
|
|
210
|
-
const rows = results.sort((a, b) => (a.rank ?? 9) - (b.rank ?? 9));
|
|
211
|
-
for (const r of rows) {
|
|
212
|
-
const state = r.fail ? `fail ${r.fail}` : `ok ${r.ms}ms`;
|
|
213
|
-
const label = r.id && r.id !== r.url ? r.id + " " : "";
|
|
214
|
-
console.log(` ${label}${r.url} ${state}`);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
} else {
|
|
199
|
+
const joinedList = loadGroupsJoined();
|
|
200
|
+
if (!joinedList.length) {
|
|
218
201
|
console.log("no groups on this node");
|
|
202
|
+
process.exit(0);
|
|
219
203
|
}
|
|
220
|
-
const
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
204
|
+
const { token } = await loadToken();
|
|
205
|
+
const fetchImpl = (url, opts) => fetch(url, { ...opts, signal: AbortSignal.timeout(1500) });
|
|
206
|
+
for (const g of joinedList) {
|
|
207
|
+
const isLeader = !g.leaderUrl;
|
|
208
|
+
let members;
|
|
209
|
+
if (isLeader) {
|
|
210
|
+
members = groups.list()[g.name]?.members || {};
|
|
211
|
+
} else {
|
|
212
|
+
try {
|
|
213
|
+
members = await refreshGroupMembers(g.name, {
|
|
214
|
+
leaderUrl: g.leaderUrl,
|
|
215
|
+
memberName: g.memberName,
|
|
216
|
+
url: g.myUrl,
|
|
217
|
+
token,
|
|
218
|
+
fetchImpl,
|
|
219
|
+
});
|
|
220
|
+
} catch (err) {
|
|
221
|
+
console.log(`${g.name} (members unavailable — leader unreachable: ${errMsg(err)})`);
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
console.log(`${g.name} (${Object.keys(members).length} members)`);
|
|
226
|
+
// probe every member endpoint concurrently for reachability + latency
|
|
227
|
+
const probes = Object.entries(members).map(([id, m]) => ({ id, url: m?.url || id }));
|
|
228
|
+
if (!isLeader && g.leaderUrl && !probes.some((p) => p.url === g.leaderUrl)) {
|
|
229
|
+
probes.push({ id: "leader", url: g.leaderUrl });
|
|
230
|
+
}
|
|
231
|
+
const results = await Promise.all(probes.map(probeHealth));
|
|
232
|
+
const rows = results.sort((a, b) => (a.rank ?? 9) - (b.rank ?? 9));
|
|
233
|
+
for (const r of rows) {
|
|
234
|
+
const state = r.fail ? `fail ${r.fail}` : `ok ${r.ms}ms`;
|
|
235
|
+
const label = r.id && r.id !== r.url ? r.id + " " : "";
|
|
236
|
+
console.log(` ${label}${r.url} ${state}`);
|
|
237
|
+
}
|
|
224
238
|
}
|
|
239
|
+
console.log(`\njoined groups (${joinedList.length}):`);
|
|
240
|
+
for (const g of joinedList) console.log(` ${g.name} ${g.leaderUrl || "(this node is the leader)"}`);
|
|
225
241
|
} else {
|
|
226
242
|
console.error("usage: mslxdff -creategroup <name> | -group sync | -group leave <name> | -group list");
|
|
227
243
|
}
|
|
@@ -288,7 +304,6 @@ function errMsg(err) { return String(err?.message || err); }
|
|
|
288
304
|
|
|
289
305
|
// Probe a member's health endpoint concurrently (v1/health preferred,
|
|
290
306
|
// falling back to /health). Returns { id, url, ms, rank } or { id, url, fail }.
|
|
291
|
-
const HEALTH_TIMEOUT_MS = 4000;
|
|
292
307
|
async function probeHealth({ id, url } = {}) {
|
|
293
308
|
if (!url) return { id, url, fail: "no url", rank: 3 };
|
|
294
309
|
const base = String(url).replace(/\/+$/, "");
|