Merge pull request #2112 from pikasTech/fix/2097-cloud-diagnostic-log

fix(hwlab-node): log cloud diagnostics
This commit is contained in:
Lyon
2026-06-25 11:04:21 +08:00
committed by GitHub
+2
View File
@@ -24,6 +24,7 @@ type PendingDispatch = {
export function createHwpodNodeWsRegistry(options: any = {}) { export function createHwpodNodeWsRegistry(options: any = {}) {
const now = options.now ?? (() => new Date().toISOString()); const now = options.now ?? (() => new Date().toISOString());
const clock = options.clock ?? (() => Date.now()); const clock = options.clock ?? (() => Date.now());
const logger = options.logger ?? console;
const connections = new Map<string, HwpodNodeConnection>(); const connections = new Map<string, HwpodNodeConnection>();
const pending = new Map<string, PendingDispatch>(); const pending = new Map<string, PendingDispatch>();
const socketConnections = new WeakMap<object, HwpodNodeConnection>(); const socketConnections = new WeakMap<object, HwpodNodeConnection>();
@@ -145,6 +146,7 @@ export function createHwpodNodeWsRegistry(options: any = {}) {
const diagnostic = normalizeDiagnostic(message.diagnostic, now()); const diagnostic = normalizeDiagnostic(message.diagnostic, now());
connection.diagnostics.push(diagnostic); connection.diagnostics.push(diagnostic);
if (connection.diagnostics.length > 50) connection.diagnostics = connection.diagnostics.slice(-50); if (connection.diagnostics.length > 50) connection.diagnostics = connection.diagnostics.slice(-50);
logger.warn?.(JSON.stringify({ event: "hwpod-node.diagnostic", nodeId: connection.nodeId || nodeId || null, connectionId: connection.id, diagnostic, valuesPrinted: false }));
sendJson(connection, { type: "ack", requestId: safeText(message.requestId) || "diagnostic", ok: true, message: "diagnostic recorded" }); sendJson(connection, { type: "ack", requestId: safeText(message.requestId) || "diagnostic", ok: true, message: "diagnostic recorded" });
return; return;
} }