From 3c0977702e190e90ae3dbe23c0b7b44bba3e46f6 Mon Sep 17 00:00:00 2001 From: Michael Lange Date: Fri, 31 Aug 2018 14:36:43 -0700 Subject: [PATCH] Example usage of the NodeStatsTracker --- ui/app/controllers/clients/client.js | 13 +++++++++++++ ui/app/routes/clients/client.js | 9 +++++++++ 2 files changed, 22 insertions(+) diff --git a/ui/app/controllers/clients/client.js b/ui/app/controllers/clients/client.js index 26dfc9b64..cdc15915c 100644 --- a/ui/app/controllers/clients/client.js +++ b/ui/app/controllers/clients/client.js @@ -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); diff --git a/ui/app/routes/clients/client.js b/ui/app/routes/clients/client.js index 9e2493030..ea040b3dc 100644 --- a/ui/app/routes/clients/client.js +++ b/ui/app/routes/clients/client.js @@ -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(); + }, });