-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
task-event.js
42 lines (34 loc) · 1003 Bytes
/
task-event.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
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import Fragment from 'ember-data-model-fragments/fragment';
import { attr } from '@ember-data/model';
import { fragmentOwner } from 'ember-data-model-fragments/attributes';
export default class TaskEvent extends Fragment {
@fragmentOwner() state;
@attr('string') type;
@attr('number') signal;
@attr('number') exitCode;
@attr('date') time;
@attr('number') timeNanos;
@attr('string') displayMessage;
get message() {
let message = simplifyTimeMessage(this.displayMessage);
return message;
}
}
function simplifyTimeMessage(message) {
return (
message?.replace(/(\d+h)?(\d+m)?(\d+\.\d+)s/g, (_, h, m, s) => {
h = h ? parseInt(h) : 0;
m = m ? parseInt(m) : 0;
s = Math.round(parseFloat(s));
m += Math.floor(s / 60);
s %= 60;
h += Math.floor(m / 60);
m %= 60;
return `${h ? h + 'h' : ''}${h || m ? m + 'm' : ''}${s}s`;
}) || message
);
}