mslxdff 0.1.19 → 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 +39 -24
- package/package.json +1 -1
package/bin/mslxdff.js
CHANGED
|
@@ -196,33 +196,48 @@ if (groupCmd && groupCmd !== "create") {
|
|
|
196
196
|
const removed = peers.removeByGroup(a);
|
|
197
197
|
console.log(before ? `left group "${a}" (${removed} member(s) removed)` : `not a member of group "${a}"`);
|
|
198
198
|
} else if (action === "list") {
|
|
199
|
-
const
|
|
200
|
-
|
|
201
|
-
if (names.length) {
|
|
202
|
-
for (const n of names) {
|
|
203
|
-
console.log(`${n} (${Object.keys(all[n].members || {}).length} members)`);
|
|
204
|
-
// probe every member endpoint concurrently to show reachability + latency
|
|
205
|
-
const probes = Object.entries(all[n].members || {}).map(([id, m]) => ({
|
|
206
|
-
id, url: m?.url,
|
|
207
|
-
}));
|
|
208
|
-
const joined = loadGroupsJoined().find((g) => g.name === n);
|
|
209
|
-
if (joined?.leaderUrl) probes.push({ id: "leader", url: joined.leaderUrl });
|
|
210
|
-
const results = await Promise.all(probes.map(probeHealth));
|
|
211
|
-
const rows = results.sort((a, b) => (a.rank ?? 9) - (b.rank ?? 9));
|
|
212
|
-
for (const r of rows) {
|
|
213
|
-
const state = r.fail ? `fail ${r.fail}` : `ok ${r.ms}ms`;
|
|
214
|
-
const label = r.id && r.id !== r.url ? r.id + " " : "";
|
|
215
|
-
console.log(` ${label}${r.url} ${state}`);
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
} else {
|
|
199
|
+
const joinedList = loadGroupsJoined();
|
|
200
|
+
if (!joinedList.length) {
|
|
219
201
|
console.log("no groups on this node");
|
|
202
|
+
process.exit(0);
|
|
220
203
|
}
|
|
221
|
-
const
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
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
|
+
}
|
|
225
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)"}`);
|
|
226
241
|
} else {
|
|
227
242
|
console.error("usage: mslxdff -creategroup <name> | -group sync | -group leave <name> | -group list");
|
|
228
243
|
}
|