refactor: enhance command timeout logging and add keepalive ping handling for improved monitoring

This commit is contained in:
MayaTheShy
2026-02-20 04:39:52 -05:00
parent a809bddd46
commit 23515728e0
2 changed files with 11 additions and 0 deletions

View File

@@ -358,6 +358,10 @@ export class Turtle extends EventEmitter {
// Set up timeout // Set up timeout
const timer = setTimeout(() => { const timer = setTimeout(() => {
const pending = this._pendingCommands.get(uuid);
if (pending) {
console.warn(`[Turtle ${this.id}] ⏰ Command timed out uuid:${uuid.substring(0, 8)} (pending: ${this._pendingCommands.size}, code: ${luaCode.substring(0, 50)})`);
}
this._pendingCommands.delete(uuid); this._pendingCommands.delete(uuid);
reject(new Error(`Command timed out after ${timeout}ms`)); reject(new Error(`Command timed out after ${timeout}ms`));
}, timeout); }, timeout);

View File

@@ -228,6 +228,7 @@ function pushCommandToBridge(turtleID, command) {
const turtle = turtles.get(turtleID); const turtle = turtles.get(turtleID);
if (turtle) { if (turtle) {
turtle.pendingCommands.push({ ...command, timestamp: Date.now() }); turtle.pendingCommands.push({ ...command, timestamp: Date.now() });
console.log(`[Bridge] Queued command for T#${turtleID} via HTTP poll (no WS bridge, ${bridgeClients.size} bridges)`);
} }
} }
} }
@@ -251,6 +252,12 @@ wss.on('connection', (ws, req) => {
try { try {
const data = JSON.parse(raw); const data = JSON.parse(raw);
// Handle keepalive pings from bridge
if (data.type === 'ping') {
ws.send(JSON.stringify({ type: 'pong' }));
return;
}
if (data.type === 'status') { if (data.type === 'status') {
// Turtle status update forwarded from bridge // Turtle status update forwarded from bridge
const turtleID = data.turtleID; const turtleID = data.turtleID;