Example of usage of the AllocationsStatsTracker

This commit is contained in:
Michael Lange 2018-08-29 17:18:42 -07:00
parent da4852a6cd
commit f5fa5101b4
2 changed files with 28 additions and 0 deletions

View file

@ -1,9 +1,14 @@
import { alias } from '@ember/object/computed';
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
import { task, timeout } from 'ember-concurrency';
import Sortable from 'nomad-ui/mixins/sortable';
import { lazyClick } from 'nomad-ui/helpers/lazy-click';
import { stats } from 'nomad-ui/utils/classes/allocation-stats-tracker';
export default Controller.extend(Sortable, {
token: service(),
queryParams: {
sortProperty: 'sort',
sortDescending: 'desc',
@ -15,6 +20,17 @@ export default Controller.extend(Sortable, {
listToSort: alias('model.states'),
sortedStates: alias('listSorted'),
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: {
gotoTask(allocation, task) {
this.transitionToRoute('allocations.allocation.task', task);

View file

@ -0,0 +1,12 @@
import Route from '@ember/routing/route';
export default Route.extend({
setupController(controller) {
this._super(...arguments);
controller.get('pollStats').perform();
},
resetController(controller) {
controller.get('pollStats').cancelAll();
},
});