Fix subscribe reconnect (rancher/rancher#3639)

This commit is contained in:
Vincent Fiduccia 2016-02-26 15:03:57 -07:00
parent 95acd09ca8
commit 6d9c68241f
3 changed files with 66 additions and 46 deletions

View File

@ -81,6 +81,8 @@ export default Ember.Route.extend({
activate() { activate() {
this._super(); this._super();
console.log('Activate socket for', this.get(`tab-session.${C.TABSESSION.PROJECT}`));
var store = this.get('store'); var store = this.get('store');
var boundTypeify = store._typeify.bind(store); var boundTypeify = store._typeify.bind(store);
@ -95,6 +97,7 @@ export default Ember.Route.extend({
var socket = Socket.create({ var socket = Socket.create({
url: url url: url
}); });
this.set('socket', socket);
socket.on('message', (event) => { socket.on('message', (event) => {
var d = JSON.parse(event.data, boundTypeify); var d = JSON.parse(event.data, boundTypeify);
@ -127,17 +130,28 @@ export default Ember.Route.extend({
this._trySend('subscribeDisconnected', this.get('tries')); this._trySend('subscribeDisconnected', this.get('tries'));
}); });
this.set('socket', socket);
socket.connect(); socket.connect();
}, },
deactivate() { deactivate() {
this._super(); this._super();
this.closeSocket();
},
resetController() {
this._super();
this.closeSocket();
},
closeSocket() {
var socket = this.get('socket'); var socket = this.get('socket');
if ( socket ) if ( socket )
{ {
socket.disconnect(); socket.disconnect();
this.set('socket', null);
} }
Ember.run.cancel(this.get('pingTimer'));
}, },
actions: { actions: {
@ -165,6 +179,7 @@ export default Ember.Route.extend({
// WebSocket disconnected // WebSocket disconnected
subscribeDisconnected: function() { subscribeDisconnected: function() {
console.log('Subscribe disconnected'); console.log('Subscribe disconnected');
this.closeSocket();
}, },
subscribePing: function() { subscribePing: function() {
@ -176,7 +191,10 @@ export default Ember.Route.extend({
this.set('pingTimer', Ember.run.later(this, function() { this.set('pingTimer', Ember.run.later(this, function() {
console.log('Subscribe missed 2 pings...'); console.log('Subscribe missed 2 pings...');
this.get('socket').connect(); if ( this.get('socket') )
{
this.get('socket').connect();
}
}, 11000)); }, 11000));
}, },
@ -280,10 +298,10 @@ export default Ember.Route.extend({
}, },
k8sResourceChanged: function(changeType, obj) { k8sResourceChanged: function(changeType, obj) {
console.log('k8s change', changeType, (obj && obj.metadata && obj.metadata.uid ? obj.metadata.uid : 'none')); //console.log('k8s change', changeType, (obj && obj.metadata && obj.metadata.uid ? obj.metadata.uid : 'none'));
if ( obj && obj.metadata && obj.metadata.uid && this.get('k8sUidBlacklist').indexOf(obj.metadata.uid) >= 0 ) if ( obj && obj.metadata && obj.metadata.uid && this.get('k8sUidBlacklist').indexOf(obj.metadata.uid) >= 0 )
{ {
console.log('^-- Ignoring', changeType, 'for removed resource'); //console.log('^-- Ignoring', changeType, 'for removed resource');
return; return;
} }

View File

@ -71,52 +71,54 @@
</div> </div>
{{/if}} {{/if}}
<table class="grid fixed" style="margin-bottom: 0;"> {{#if accessEnabled}}
<thead> <table class="grid fixed" style="margin-bottom: 0;">
<tr> <thead>
{{sortable-th sortable=this action="changeSort" name="name"}}
{{sortable-th sortable=this action="changeSort" name="type"}}
{{sortable-th sortable=this action="changeSort" name="role"}}
{{#if showEdit}}<th width="40">&nbsp;</th>{{/if}}
</tr>
</thead>
<tbody>
{{#each arranged as |member|}}
<tr> <tr>
<td> {{sortable-th sortable=this action="changeSort" name="name"}}
{{identity-block identity=member}} {{sortable-th sortable=this action="changeSort" name="type"}}
</td> {{sortable-th sortable=this action="changeSort" name="role"}}
<td>{{member.displayType}}</td> {{#if showEdit}}<th width="40">&nbsp;</th>{{/if}}
<td> </tr>
{{#if showEdit}} </thead>
<select class="form-control input-sm" onchange={{action (mut member.role) value="target.value"}}> <tbody>
{{#each roleOptions as |choice|}} {{#each arranged as |member|}}
<option value={{choice.value}} selected={{eq member.role choice.value}}>{{choice.label}}</option> <tr>
{{/each}}
</select>
{{else}}
{{uc-first member.role}}
{{/if}}
</td>
{{#if showEdit}}
<td> <td>
{{#if accessEnabled}} {{identity-block identity=member}}
<button class="btn-circle btn-sm pull-right gh-action" {{action "removeMember" member}}><i class="icon icon-x-circle"/></button> </td>
<td>{{member.displayType}}</td>
<td>
{{#if showEdit}}
<select class="form-control input-sm" onchange={{action (mut member.role) value="target.value"}}>
{{#each roleOptions as |choice|}}
<option value={{choice.value}} selected={{eq member.role choice.value}}>{{choice.label}}</option>
{{/each}}
</select>
{{else}} {{else}}
&nbsp; {{uc-first member.role}}
{{/if}} {{/if}}
</td> </td>
{{/if}} {{#if showEdit}}
</tr> <td>
{{else}} {{#if accessEnabled}}
<tr> <button class="btn-circle btn-sm pull-right gh-action" {{action "removeMember" member}}><i class="icon icon-x-circle"/></button>
<td colspan="3" class="text-center text-muted"> {{else}}
{{if showEdit 'No members yet, add at least one owner.' 'This project has no members.'}} &nbsp;
</td> {{/if}}
</tr> </td>
{{/each}} {{/if}}
</tbody> </tr>
</table> {{else}}
<tr>
<td colspan="3" class="text-center text-muted">
{{if showEdit 'No members yet, add at least one owner.' 'This project has no members.'}}
</td>
</tr>
{{/each}}
</tbody>
</table>
{{/if}}
</div> </div>
</div> </div>
</div> </div>

View File

@ -7,7 +7,7 @@ export default Ember.Controller.extend({
docsBase: C.EXT_REFERENCES.DOCS, docsBase: C.EXT_REFERENCES.DOCS,
thingsChanged: function() { thingsChanged: function() {
console.log(this.get('application.currentRouteName'),this.get('model.hosts.length'),this.get('model.services.length')); //console.log(this.get('application.currentRouteName'),this.get('model.hosts.length'),this.get('model.services.length'));
if ( this.get('application.currentRouteName') === 'splash') if ( this.get('application.currentRouteName') === 'splash')
{ {
if ( this.get('model.hosts.length') && this.get('model.services.length') ) if ( this.get('model.hosts.length') && this.get('model.services.length') )