##// END OF EJS Templates
add sticky `Connection lost` notification...
Min RK -
Show More
@@ -132,6 +132,13 b' define(['
132 132 knw.warning("Connecting to kernel");
133 133 });
134 134
135 this.events.on('kernel_connection_dead.Kernel', function (evt, info) {
136 knw.danger("Connection lost", undefined, function () {
137 // schedule reconnect a short time in the future, don't reconnect immediately
138 setTimeout($.proxy(info.kernel.reconnect, info.kernel), 500);
139 }, {title: 'click to reconnect'});
140 });
141
135 142 this.events.on('kernel_connected.Kernel', function () {
136 143 knw.info("Connected", 500);
137 144 });
@@ -66,6 +66,7 b' define(['
66 66
67 67 this._autorestart_attempt = 0;
68 68 this._reconnect_attempt = 0;
69 this.reconnect_limit = 7;
69 70 };
70 71
71 72 /**
@@ -335,7 +336,11 b' define(['
335 336 if (this.is_connected()) {
336 337 return;
337 338 }
338 this.events.trigger('kernel_reconnecting.Kernel', {kernel: this});
339 this._reconnect_attempt = this._reconnect_attempt + 1;
340 this.events.trigger('kernel_reconnecting.Kernel', {
341 kernel: this,
342 attempt: this._reconnect_attempt,
343 });
339 344 this.start_channels();
340 345 };
341 346
@@ -527,20 +532,27 b' define(['
527 532 this.events.trigger('kernel_disconnected.Kernel', {kernel: this});
528 533 if (error) {
529 534 console.log('WebSocket connection failed: ', ws_url);
530 this._reconnect_attempt = this._reconnect_attempt + 1;
531 535 this.events.trigger('kernel_connection_failed.Kernel', {kernel: this, ws_url: ws_url, attempt: this._reconnect_attempt});
532 536 }
533 if (this._reconnect_attempt < 7) {
537 this._schedule_reconnect();
538 };
539
540 Kernel.prototype._schedule_reconnect = function () {
541 // function to call when kernel connection is lost
542 // schedules reconnect, or fires 'connection_dead' if reconnect limit is hit
543 if (this._reconnect_attempt < this.reconnect_limit) {
534 544 var timeout = Math.pow(2, this._reconnect_attempt);
535 545 console.log("Connection lost, reconnecting in " + timeout + " seconds.");
536 546 setTimeout($.proxy(this.reconnect, this), 1e3 * timeout);
537 547 } else {
538 this._reconnect_attempt = 1;
539 this.events.trigger('kernel_connection_given_up.Kernel', {kernel: this, ws_url: ws_url, attempt: this._reconnect_attempt});
548 this.events.trigger('kernel_connection_dead.Kernel', {
549 kernel: this,
550 reconnect_attempt: this._reconnect_attempt,
551 });
540 552 console.log("Failed to reconnect, giving up.");
541 553 }
542 554 };
543
555
544 556 /**
545 557 * Close the websocket channels. After successful close, the value
546 558 * in `this.channels[channel_name]` will be null.
General Comments 0
You need to be logged in to leave comments. Login now