line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Cinnamon::Runner; |
2
|
3
|
|
|
3
|
|
17
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
100
|
|
3
|
3
|
|
|
3
|
|
15
|
use warnings; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
75
|
|
4
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
14
|
use Cinnamon qw(CTX); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
132
|
|
6
|
3
|
|
|
3
|
|
1494
|
use Cinnamon::Logger; |
|
3
|
|
|
|
|
10
|
|
|
3
|
|
|
|
|
247
|
|
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
3552
|
use Coro; |
|
3
|
|
|
|
|
37991
|
|
|
3
|
|
|
|
|
272
|
|
9
|
3
|
|
|
3
|
|
2620
|
use Coro::Select; |
|
3
|
|
|
|
|
30865
|
|
|
3
|
|
|
|
|
15
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub start { |
12
|
11
|
|
|
11
|
0
|
22
|
my ($class, $hosts, $task) = @_; |
13
|
11
|
|
|
|
|
21
|
my $all_results = {}; |
14
|
11
|
|
|
|
|
29
|
$hosts = [ @$hosts ]; |
15
|
|
|
|
|
|
|
|
16
|
11
|
|
|
|
|
37
|
my $task_name = $task->name; |
17
|
11
|
|
50
|
|
|
31
|
my $concurrency_setting = CTX->get_param('concurrency') || {}; |
18
|
11
|
|
50
|
|
|
49
|
my $concurrency = $concurrency_setting->{$task_name} || scalar @$hosts; |
19
|
|
|
|
|
|
|
|
20
|
11
|
|
|
|
|
53
|
while (my @target_hosts = splice @$hosts, 0, $concurrency) { |
21
|
11
|
|
|
|
|
16
|
my @coros; |
22
|
|
|
|
|
|
|
|
23
|
11
|
|
|
|
|
23
|
for my $host (@target_hosts) { |
24
|
|
|
|
|
|
|
my $coro = async { |
25
|
11
|
|
|
11
|
|
85
|
my $result = $class->execute($host, $task); |
26
|
11
|
|
|
|
|
109
|
$all_results->{$host} = $result; |
27
|
11
|
|
|
|
|
143
|
}; |
28
|
|
|
|
|
|
|
|
29
|
11
|
|
|
|
|
15068
|
push @coros, $coro; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
11
|
|
|
|
|
345
|
$_->join for @coros; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
11
|
|
|
|
|
359
|
return $all_results; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub execute { |
39
|
11
|
|
|
11
|
0
|
26
|
my ($class, $host, $task) = @_; |
40
|
|
|
|
|
|
|
|
41
|
11
|
|
|
|
|
55
|
my $result = { host => $host, error => 0 }; |
42
|
|
|
|
|
|
|
|
43
|
11
|
|
|
|
|
16
|
local $@; |
44
|
11
|
|
|
|
|
20
|
eval { $task->execute($host) }; |
|
11
|
|
|
|
|
76
|
|
45
|
11
|
100
|
|
|
|
65
|
if ($@) { |
46
|
3
|
|
|
|
|
9
|
chomp $@; |
47
|
3
|
|
|
|
|
18
|
log error => sprintf '[%s] %s', $host, $@; |
48
|
3
|
|
|
|
|
7
|
$result->{error} = 1; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
11
|
|
|
|
|
29
|
return $result; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
1; |