line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package Kevin::Commands::Util; |
3
|
|
|
|
|
|
|
$Kevin::Commands::Util::VERSION = '0.5.2'; # TRIAL |
4
|
2
|
|
|
2
|
|
163262
|
use Mojo::Base -strict; |
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
13
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# Borrowed from https://github.com/docker/go-units/blob/master/duration.go |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub _human_duration { |
9
|
68
|
|
|
68
|
|
28130
|
my $seconds = shift; |
10
|
|
|
|
|
|
|
|
11
|
68
|
100
|
|
|
|
159
|
return 'less than a second' if $seconds < 1; |
12
|
67
|
100
|
|
|
|
114
|
return '1 second' if $seconds == 1; |
13
|
66
|
100
|
|
|
|
430
|
return sprintf '%d seconds', $seconds if $seconds < 60; |
14
|
|
|
|
|
|
|
|
15
|
58
|
|
|
|
|
105
|
my $minutes = int($seconds / 60); |
16
|
58
|
100
|
|
|
|
112
|
return 'about a minute' if $minutes == 1; |
17
|
50
|
100
|
|
|
|
94
|
return sprintf '%d minutes', $minutes if $minutes < 46; |
18
|
|
|
|
|
|
|
|
19
|
42
|
|
|
|
|
69
|
my $hours = int($seconds / (60 * 60) + 0.5); |
20
|
42
|
100
|
|
|
|
68
|
return 'about an hour' if $hours == 1; |
21
|
38
|
100
|
|
|
|
88
|
return sprintf '%d hours', $hours if $hours < 48; |
22
|
26
|
100
|
|
|
|
58
|
return sprintf '%d days', $hours / 24 if $hours < 24 * 7 * 2; |
23
|
20
|
100
|
|
|
|
62
|
return sprintf '%d weeks', $hours / (24 * 7) if $hours < 24 * 30 * 2; |
24
|
14
|
100
|
|
|
|
68
|
return sprintf '%d months', $hours / (24 * 30) if $hours < 24 * 365 * 2; |
25
|
|
|
|
|
|
|
|
26
|
3
|
|
|
|
|
13
|
return sprintf '%d years', $hours / (24 * 365); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub _created_since { |
30
|
0
|
|
|
0
|
|
|
ucfirst _human_duration(shift) . ' ago'; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub _running_since { |
34
|
0
|
|
|
0
|
|
|
'Up ' . _human_duration(shift); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub _job_status { |
38
|
0
|
|
|
0
|
|
|
my ($info, $now) = (shift, shift); |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
my $state = $info->{state}; |
41
|
0
|
0
|
|
|
|
|
if ($state eq 'active') { |
42
|
|
|
|
|
|
|
return 'Waiting ' . _human_duration($now - $info->{delayed}) |
43
|
0
|
0
|
|
|
|
|
if $info->{delayed}; |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
return 'Running'; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
0
|
0
|
0
|
|
|
|
if ($state eq 'failed' || $state eq 'finished') { |
49
|
|
|
|
|
|
|
return |
50
|
0
|
|
|
|
|
|
ucfirst $state . ' ' . _human_duration($now - $info->{finished}) . ' ago'; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
return 'Inactive'; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
1; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
__END__ |