UI - fix the top level polling and use ember-concurrency (#5433)
* fix the top level pollling and use ember-concurrency * make suggested changes
This commit is contained in:
parent
8bf1598bff
commit
984462f22b
|
@ -1,10 +1,9 @@
|
|||
import { inject as service } from '@ember/service';
|
||||
import { cancel, later } from '@ember/runloop';
|
||||
import { computed } from '@ember/object';
|
||||
import { on } from '@ember/object/evented';
|
||||
import { reject } from 'rsvp';
|
||||
import Route from '@ember/routing/route';
|
||||
import { getOwner } from '@ember/application';
|
||||
import { task, timeout } from 'ember-concurrency';
|
||||
import Ember from 'ember';
|
||||
import ClusterRoute from 'vault/mixins/cluster-route';
|
||||
import ModelBoundaryRoute from 'vault/mixins/model-boundary-route';
|
||||
|
@ -67,39 +66,28 @@ export default Route.extend(ModelBoundaryRoute, ClusterRoute, {
|
|||
|
||||
model(params) {
|
||||
const id = this.getClusterId(params);
|
||||
|
||||
return this.get('store').findRecord('cluster', id);
|
||||
},
|
||||
|
||||
stopPoll: on('deactivate', function() {
|
||||
cancel(this.get('timer'));
|
||||
}),
|
||||
|
||||
poll() {
|
||||
poll: task(function*() {
|
||||
// when testing, the polling loop causes promises to never settle so acceptance tests hang
|
||||
// to get around that, we just disable the poll in tests
|
||||
return Ember.testing
|
||||
? null
|
||||
: later(() => {
|
||||
this.controller
|
||||
.get('model')
|
||||
.reload()
|
||||
.then(
|
||||
() => {
|
||||
this.set('timer', this.poll());
|
||||
return this.transitionToTargetRoute();
|
||||
},
|
||||
() => {
|
||||
this.set('timer', this.poll());
|
||||
}
|
||||
);
|
||||
}, POLL_INTERVAL_MS);
|
||||
},
|
||||
do {
|
||||
yield timeout(POLL_INTERVAL_MS);
|
||||
try {
|
||||
yield this.controller.model.reload();
|
||||
yield this.transitionToTargetRoute();
|
||||
} catch (e) {
|
||||
// we want to keep polling here
|
||||
}
|
||||
} while (!Ember.testing);
|
||||
})
|
||||
.cancelOn('deactivate')
|
||||
.keepLatest(),
|
||||
|
||||
afterModel(model) {
|
||||
this.get('currentCluster').setCluster(model);
|
||||
this._super(...arguments);
|
||||
this.poll();
|
||||
this.get('currentCluster').setCluster(model);
|
||||
|
||||
// Check that namespaces is enabled and if not,
|
||||
// clear the namespace by transition to this route w/o it
|
||||
|
@ -109,6 +97,11 @@ export default Route.extend(ModelBoundaryRoute, ClusterRoute, {
|
|||
return this.transitionToTargetRoute();
|
||||
},
|
||||
|
||||
setupController() {
|
||||
this._super(...arguments);
|
||||
this.poll.perform();
|
||||
},
|
||||
|
||||
actions: {
|
||||
error(e) {
|
||||
if (e.httpStatus === 503 && e.errors[0] === 'Vault is sealed') {
|
||||
|
|
Loading…
Reference in New Issue