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';
|
2022-04-21 17:57:18 +00:00
|
|
|
|
2022-03-08 17:28:36 +00:00
|
|
|
import {
|
|
|
|
classNames,
|
|
|
|
tagName,
|
|
|
|
attributeBindings,
|
|
|
|
} from '@ember-decorators/component';
|
2020-06-10 13:49:16 +00:00
|
|
|
import classic from 'ember-classic-decorator';
|
2018-09-21 00:48:18 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@classic
|
|
|
|
@tagName('tr')
|
|
|
|
@classNames('task-row', 'is-interactive')
|
2022-03-08 17:28:36 +00:00
|
|
|
@attributeBindings('data-test-task-row')
|
2020-06-10 13:49:16 +00:00
|
|
|
export default class TaskRow extends Component {
|
|
|
|
@service store;
|
|
|
|
@service token;
|
|
|
|
@service('stats-trackers-registry') statsTrackersRegistry;
|
2018-09-21 00:48:18 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
task = null;
|
2018-09-21 00:48:18 +00:00
|
|
|
|
|
|
|
// Internal state
|
2020-06-10 13:49:16 +00:00
|
|
|
statsError = false;
|
2018-09-21 00:48:18 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@computed
|
|
|
|
get enablePolling() {
|
2020-06-09 21:03:28 +00:00
|
|
|
return !Ember.testing;
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2018-09-21 00:48:18 +00:00
|
|
|
|
|
|
|
// Since all tasks for an allocation share the same tracker, use the registry
|
2021-02-17 21:01:44 +00:00
|
|
|
@computed('task.{allocation,isRunning}')
|
2020-06-10 13:49:16 +00:00
|
|
|
get stats() {
|
2020-06-10 14:07:16 +00:00
|
|
|
if (!this.get('task.isRunning')) return undefined;
|
2018-12-10 23:25:48 +00:00
|
|
|
|
2019-03-26 07:46:44 +00:00
|
|
|
return this.statsTrackersRegistry.getTracker(this.get('task.allocation'));
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2018-09-21 00:48:18 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@computed('task.name', 'stats.tasks.[]')
|
|
|
|
get taskStats() {
|
2020-06-10 14:07:16 +00:00
|
|
|
if (!this.stats) return undefined;
|
2018-12-10 23:25:48 +00:00
|
|
|
|
|
|
|
return this.get('stats.tasks').findBy('task', this.get('task.name'));
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2018-09-21 00:48:18 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@alias('taskStats.cpu.lastObject') cpu;
|
|
|
|
@alias('taskStats.memory.lastObject') memory;
|
2018-09-21 00:48:18 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
onClick() {}
|
2018-09-21 00:48:18 +00:00
|
|
|
|
|
|
|
click(event) {
|
2019-03-26 07:46:44 +00:00
|
|
|
lazyClick([this.onClick, event]);
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2018-09-21 00:48:18 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
@(task(function* () {
|
2018-09-21 00:48:18 +00:00
|
|
|
do {
|
2019-03-26 07:46:44 +00:00
|
|
|
if (this.stats) {
|
2018-12-10 23:25:48 +00:00
|
|
|
try {
|
2021-12-28 14:45:20 +00:00
|
|
|
yield this.get('stats.poll').linked().perform();
|
2018-12-10 23:25:48 +00:00
|
|
|
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);
|
2020-06-10 13:49:16 +00:00
|
|
|
}).drop())
|
|
|
|
fetchStats;
|
2018-09-21 00:48:18 +00:00
|
|
|
|
|
|
|
didReceiveAttrs() {
|
2021-12-28 14:45:20 +00:00
|
|
|
super.didReceiveAttrs();
|
2018-09-21 00:48:18 +00:00
|
|
|
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
|
|
|
}
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
|
|
|
}
|