line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package Kevin::Commands::Util; |
3
|
|
|
|
|
|
|
$Kevin::Commands::Util::VERSION = '0.7.1'; |
4
|
3
|
|
|
3
|
|
162204
|
use Mojo::Base -strict; |
|
3
|
|
|
|
|
103258
|
|
|
3
|
|
|
|
|
22
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# Borrowed from https://github.com/docker/go-units/blob/master/duration.go |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub _human_duration { |
9
|
68
|
|
|
68
|
|
27779
|
my $seconds = shift; |
10
|
|
|
|
|
|
|
|
11
|
68
|
100
|
|
|
|
148
|
return 'less than a second' if $seconds < 1; |
12
|
67
|
100
|
|
|
|
98
|
return '1 second' if $seconds == 1; |
13
|
66
|
100
|
|
|
|
123
|
return sprintf '%d seconds', $seconds if $seconds < 60; |
14
|
|
|
|
|
|
|
|
15
|
58
|
|
|
|
|
100
|
my $minutes = int($seconds / 60); |
16
|
58
|
100
|
|
|
|
96
|
return 'about a minute' if $minutes == 1; |
17
|
50
|
100
|
|
|
|
94
|
return sprintf '%d minutes', $minutes if $minutes < 46; |
18
|
|
|
|
|
|
|
|
19
|
42
|
|
|
|
|
66
|
my $hours = int($seconds / (60 * 60) + 0.5); |
20
|
42
|
100
|
|
|
|
66
|
return 'about an hour' if $hours == 1; |
21
|
38
|
100
|
|
|
|
110
|
return sprintf '%d hours', $hours if $hours < 48; |
22
|
26
|
100
|
|
|
|
56
|
return sprintf '%d days', $hours / 24 if $hours < 24 * 7 * 2; |
23
|
20
|
100
|
|
|
|
46
|
return sprintf '%d weeks', $hours / (24 * 7) if $hours < 24 * 30 * 2; |
24
|
14
|
100
|
|
|
|
55
|
return sprintf '%d months', $hours / (24 * 30) if $hours < 24 * 365 * 2; |
25
|
|
|
|
|
|
|
|
26
|
3
|
|
|
|
|
15
|
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__ |