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