diff --git a/ui/app/components/allocation-row.js b/ui/app/components/allocation-row.js index 088c07a82..c173b794c 100644 --- a/ui/app/components/allocation-row.js +++ b/ui/app/components/allocation-row.js @@ -1,7 +1,9 @@ +import Ember from 'ember'; import { inject as service } from '@ember/service'; import Component from '@ember/component'; import { run } from '@ember/runloop'; import { lazyClick } from '../helpers/lazy-click'; +import { task, timeout } from 'ember-concurrency'; export default Component.extend({ store: service(), @@ -15,6 +17,10 @@ export default Component.extend({ // Used to determine whether the row should mention the node or the job context: null, + // Internal state + stats: null, + statsError: false, + onClick() {}, click(event) { @@ -45,8 +51,32 @@ export default Component.extend({ // being resolved through the store (store.findAll('job')). The // workaround is to persist the jobID as a string on the allocation // and manually re-link the two records here. + const allocation = this.get('allocation'); + + if (allocation) { + this.get('fetchStats').perform(allocation); + } else { + this.get('fetchStats').cancelAll(); + this.set('stats', null); + } run.scheduleOnce('afterRender', this, qualifyJob); }, + + fetchStats: task(function*(allocation) { + const maxTiming = 5500; + const backoffSequence = [500, 800, 1300, 2100, 3400]; + + do { + try { + const stats = yield allocation.fetchStats(); + this.set('stats', stats); + } catch (error) { + this.set('statsError', true); + break; + } + yield timeout(backoffSequence.shift() || maxTiming); + } while (!Ember.testing); + }).drop(), }); function qualifyJob() { diff --git a/ui/app/templates/components/allocation-row.hbs b/ui/app/templates/components/allocation-row.hbs index 7656960e5..305a89372 100644 --- a/ui/app/templates/components/allocation-row.hbs +++ b/ui/app/templates/components/allocation-row.hbs @@ -23,37 +23,41 @@