refactor: enhance command timeout logging and add keepalive ping handling for improved monitoring
This commit is contained in:
@@ -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);
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user