Example usage of the NodeStatsTracker

This commit is contained in:
Michael Lange
2018-08-31 14:36:43 -07:00
parent c455a399dd
commit 3c0977702e
2 changed files with 22 additions and 0 deletions

View File

@@ -1,8 +1,10 @@
import { alias } from '@ember/object/computed';
import Controller from '@ember/controller';
import { computed } from '@ember/object';
import { task, timeout } from 'ember-concurrency';
import Sortable from 'nomad-ui/mixins/sortable';
import Searchable from 'nomad-ui/mixins/searchable';
import { stats } from 'nomad-ui/utils/classes/node-stats-tracker';
export default Controller.extend(Sortable, Searchable, {
queryParams: {
@@ -34,6 +36,17 @@ export default Controller.extend(Sortable, Searchable, {
return this.get('model.drivers').sortBy('name');
}),
stats: stats('model', function statsFetch() {
return url => this.get('token').authorizedRequest(url);
}),
pollStats: task(function*() {
while (true) {
yield this.get('stats').poll();
yield timeout(1000);
}
}),
actions: {
gotoAllocation(allocation) {
this.transitionToRoute('allocations.allocation', allocation);

View File

@@ -38,4 +38,13 @@ export default Route.extend(WithWatchers, {
watchAllocations: watchRelationship('allocations'),
watchers: collect('watch', 'watchAllocations'),
setupController(controller) {
this._super(...arguments);
controller.get('pollStats').perform();
},
resetController(controller) {
controller.get('pollStats').cancelAll();
},
});