1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Back off comms reconnect attempts after prolonged failures

This commit is contained in:
Nick O'Leary 2016-04-10 17:28:28 +01:00
parent 08794bad74
commit 0c227be02d
3 changed files with 42 additions and 6 deletions

View File

@ -18,7 +18,8 @@ RED.comms = (function() {
var errornotification = null; var errornotification = null;
var clearErrorTimer = null; var clearErrorTimer = null;
var connectCountdownTimer = null;
var connectCountdown = 10;
var subscriptions = {}; var subscriptions = {};
var ws; var ws;
var pendingAuth = false; var pendingAuth = false;
@ -82,14 +83,39 @@ RED.comms = (function() {
} }
}; };
ws.onclose = function() { ws.onclose = function() {
if (reconnectAttempts > 5 && errornotification == null) { if (clearErrorTimer) {
errornotification = RED.notify(RED._("notification.error",{message:RED._("notification.errors.lostConnection")}),"error",true);
} else if (clearErrorTimer) {
clearTimeout(clearErrorTimer); clearTimeout(clearErrorTimer);
clearErrorTimer = null; clearErrorTimer = null;
} }
reconnectAttempts++; reconnectAttempts++;
if (reconnectAttempts < 10) {
setTimeout(connectWS,1000); setTimeout(connectWS,1000);
if (reconnectAttempts > 5 && errornotification == null) {
errornotification = RED.notify(RED._("notification.errors.lostConnection"),"error",true);
}
} else if (reconnectAttempts < 20) {
setTimeout(connectWS,2000);
} else {
connectCountdown = 60;
connectCountdownTimer = setInterval(function() {
connectCountdown--;
if (connectCountdown === 0) {
errornotification.update(RED._("notification.errors.lostConnection"));
clearInterval(connectCountdownTimer);
connectWS();
} else {
var msg = RED._("notification.errors.lostConnectionReconnect",{time: connectCountdown})+' <a href="#">'+ RED._("notification.errors.lostConnectionTry")+'</a>';
errornotification.update(msg);
$(errornotification).find("a").click(function(e) {
e.preventDefault();
errornotification.update(RED._("notification.errors.lostConnection"));
clearInterval(connectCountdownTimer);
connectWS();
})
}
},1000);
}
} }
} }

View File

@ -48,6 +48,14 @@ RED.notify = (function() {
}); });
}; };
})(); })();
n.update = (function() {
var nn = n;
return function(msg) {
nn.innerHTML = msg;
}
})();
if (!fixed) { if (!fixed) {
$(n).click((function() { $(n).click((function() {
var nn = n; var nn = n;

View File

@ -59,7 +59,9 @@
"error": "<strong>Error</strong>: __message__", "error": "<strong>Error</strong>: __message__",
"errors": { "errors": {
"lostConnection": "Lost connection to server", "lostConnection": "Lost connection to server, reconnecting...",
"lostConnectionReconnect": "Lost connection to server, reconnecting in __time__s.",
"lostConnectionTry": "Try now",
"cannotAddSubflowToItself": "Cannot add subflow to itself", "cannotAddSubflowToItself": "Cannot add subflow to itself",
"cannotAddCircularReference": "Cannot add subflow - circular reference detected" "cannotAddCircularReference": "Cannot add subflow - circular reference detected"
} }