-
Notifications
You must be signed in to change notification settings - Fork 2k
/
Copy pathtask-row.js
85 lines (69 loc) · 1.98 KB
/
task-row.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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,
attributeBindings,
} from '@ember-decorators/component';
import classic from 'ember-classic-decorator';
@classic
@tagName('tr')
@classNames('task-row', 'is-interactive')
@attributeBindings('data-test-task-row')
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').linked().perform();
this.set('statsError', false);
} catch (error) {
this.set('statsError', true);
}
}
yield timeout(500);
} while (this.enablePolling);
}).drop())
fetchStats;
didReceiveAttrs() {
super.didReceiveAttrs();
const allocation = this.get('task.allocation');
if (allocation) {
this.fetchStats.perform();
} else {
this.fetchStats.cancelAll();
}
}
}