2018-09-21 00:48:18 +00:00
|
|
|
import Ember from 'ember';
|
|
|
|
import Component from '@ember/component';
|
|
|
|
import { inject as service } from '@ember/service';
|
|
|
|
import { computed } from '@ember/object';
|
|
|
|
import { alias } from '@ember/object/computed';
|
|
|
|
import { task, timeout } from 'ember-concurrency';
|
|
|
|
import { lazyClick } from '../helpers/lazy-click';
|
|
|
|
|
|
|
|
export default Component.extend({
|
|
|
|
store: service(),
|
|
|
|
token: service(),
|
|
|
|
statsTrackersRegistry: service('stats-trackers-registry'),
|
|
|
|
|
|
|
|
tagName: 'tr',
|
|
|
|
classNames: ['task-row', 'is-interactive'],
|
|
|
|
|
|
|
|
task: null,
|
|
|
|
|
|
|
|
// Internal state
|
|
|
|
statsError: false,
|
|
|
|
|
|
|
|
enablePolling: computed(() => !Ember.testing),
|
|
|
|
|
|
|
|
// Since all tasks for an allocation share the same tracker, use the registry
|
2018-12-10 23:25:48 +00:00
|
|
|
stats: computed('task', 'task.isRunning', function() {
|
|
|
|
if (!this.get('task.isRunning')) return;
|
|
|
|
|
2019-03-26 07:46:44 +00:00
|
|
|
return this.statsTrackersRegistry.getTracker(this.get('task.allocation'));
|
2018-09-21 00:48:18 +00:00
|
|
|
}),
|
|
|
|
|
|
|
|
taskStats: computed('task.name', 'stats.tasks.[]', function() {
|
2019-03-26 07:46:44 +00:00
|
|
|
if (!this.stats) return;
|
2018-12-10 23:25:48 +00:00
|
|
|
|
|
|
|
return this.get('stats.tasks').findBy('task', this.get('task.name'));
|
2018-09-21 00:48:18 +00:00
|
|
|
}),
|
|
|
|
|
|
|
|
cpu: alias('taskStats.cpu.lastObject'),
|
|
|
|
memory: alias('taskStats.memory.lastObject'),
|
|
|
|
|
|
|
|
onClick() {},
|
|
|
|
|
|
|
|
click(event) {
|
2019-03-26 07:46:44 +00:00
|
|
|
lazyClick([this.onClick, event]);
|
2018-09-21 00:48:18 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
fetchStats: task(function*() {
|
|
|
|
do {
|
2019-03-26 07:46:44 +00:00
|
|
|
if (this.stats) {
|
2018-12-10 23:25:48 +00:00
|
|
|
try {
|
|
|
|
yield this.get('stats.poll').perform();
|
|
|
|
this.set('statsError', false);
|
|
|
|
} catch (error) {
|
|
|
|
this.set('statsError', true);
|
|
|
|
}
|
2018-09-21 00:48:18 +00:00
|
|
|
}
|
2018-12-10 23:25:48 +00:00
|
|
|
|
2018-09-21 00:48:18 +00:00
|
|
|
yield timeout(500);
|
2019-03-26 07:46:44 +00:00
|
|
|
} while (this.enablePolling);
|
2018-09-21 00:48:18 +00:00
|
|
|
}).drop(),
|
|
|
|
|
|
|
|
didReceiveAttrs() {
|
|
|
|
const allocation = this.get('task.allocation');
|
|
|
|
|
|
|
|
if (allocation) {
|
2019-03-26 07:46:44 +00:00
|
|
|
this.fetchStats.perform();
|
2018-09-21 00:48:18 +00:00
|
|
|
} else {
|
2019-03-26 07:46:44 +00:00
|
|
|
this.fetchStats.cancelAll();
|
2018-09-21 00:48:18 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|