open-nomad/ui/app/components/task-row.js
Buck Doyle e9e52e0dfe
Update Ember/Ember CLI to 3.20 (#9641)
This doesn’t include Ember Data, as we are still back on 3.12.

Most changes are deprecation updates, linting fixes, and dependencies. It can
be read commit-by-commit, though many of them are mechanical and skimmable.
For the new linting exclusions, I’ve added them to the Tech Debt list.

The decrease in test count is because linting is no longer included in ember test.

There’s a new deprecation warning in the logs that can be fixed by updating Ember
Power Select but when I tried that it caused it to render incorrectly, so I decided to
ignore it for now and address it separately.
2021-02-17 15:01:44 -06:00

79 lines
1.9 KiB
JavaScript

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';
import { classNames, tagName } from '@ember-decorators/component';
import classic from 'ember-classic-decorator';
@classic
@tagName('tr')
@classNames('task-row', 'is-interactive')
export default class TaskRow extends Component {
@service store;
@service token;
@service('stats-trackers-registry') statsTrackersRegistry;
task = null;
// Internal state
statsError = false;
@computed
get enablePolling() {
return !Ember.testing;
}
// Since all tasks for an allocation share the same tracker, use the registry
@computed('task.{allocation,isRunning}')
get stats() {
if (!this.get('task.isRunning')) return undefined;
return this.statsTrackersRegistry.getTracker(this.get('task.allocation'));
}
@computed('task.name', 'stats.tasks.[]')
get taskStats() {
if (!this.stats) return undefined;
return this.get('stats.tasks').findBy('task', this.get('task.name'));
}
@alias('taskStats.cpu.lastObject') cpu;
@alias('taskStats.memory.lastObject') memory;
onClick() {}
click(event) {
lazyClick([this.onClick, event]);
}
@(task(function*() {
do {
if (this.stats) {
try {
yield this.get('stats.poll').perform();
this.set('statsError', false);
} catch (error) {
this.set('statsError', true);
}
}
yield timeout(500);
} while (this.enablePolling);
}).drop())
fetchStats;
didReceiveAttrs() {
const allocation = this.get('task.allocation');
if (allocation) {
this.fetchStats.perform();
} else {
this.fetchStats.cancelAll();
}
}
}