| 1 | package Cinnamon::Runner; | ||||||||||||
| 2 | 3 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | |||||||||||||
| 5 | 3 | ▶ | use Cinnamon qw(CTX); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 3 | ▶ | use Cinnamon::Logger; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | |||||||||||||
| 8 | 3 | ▶ | use Coro; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 3 | ▶ | use Coro::Select; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | |||||||||||||
| 11 | 11 | ▶ | sub start { | ||||||||||
|
Subroutine
start: called CC=6 SCAR=18.0
Pod
undocumented
| |||||||||||||
| 12 | 11 | my ($class, $hosts, $task) = @_; | |||||||||||
| 13 | 11 | my $all_results = {}; | |||||||||||
| 14 | 11 | $hosts = [ @$hosts ]; | |||||||||||
| 15 | |||||||||||||
| 16 | 11 | my $task_name = $task->name; | |||||||||||
| 17 | 11 | ▶ | my $concurrency_setting = CTX->get_param('concurrency') || {}; | ||||||||||
|
Condition50%1/2
CTX()->get_param('concurrency') || {}
MC/DC0%0/1
CTX()->get_param('concurrency') || {}
CTX()->get_param('concurrency')
Truth table50%1/2
A
A= CTX()->get_param('concurrency')
| |||||||||||||
| 18 | 11 | ▶ | my $concurrency = $concurrency_setting->{$task_name} || scalar @$hosts; | ||||||||||
|
Condition50%1/2
$concurrency_setting->{$task_name} || scalar @$hosts
MC/DC0%0/1
$concurrency_setting->{$task_name} || scalar @$hosts
$concurrency_setting->{$task_name}
Truth table50%1/2
A
A= $concurrency_setting->{$task_name}
| |||||||||||||
| 19 | |||||||||||||
| 20 | 11 | ▶ | while (my @target_hosts = splice @$hosts, 0, $concurrency) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 21 | 11 | my @coros; | |||||||||||
| 22 | |||||||||||||
| 23 | 11 | for my $host (@target_hosts) { | |||||||||||
| 24 | 11 | ▶ | my $coro = async { | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 25 | 11 | my $result = $class->execute($host, $task); | |||||||||||
| 26 | 11 | $all_results->{$host} = $result; | |||||||||||
| 27 | 11 | }; | |||||||||||
| 28 | |||||||||||||
| 29 | 11 | push @coros, $coro; | |||||||||||
| 30 | } | ||||||||||||
| 31 | |||||||||||||
| 32 | 11 | $_->join for @coros; | |||||||||||
| 33 | } | ||||||||||||
| 34 | |||||||||||||
| 35 | 11 | return $all_results; | |||||||||||
| 36 | } | ||||||||||||
| 37 | |||||||||||||
| 38 | 11 | ▶ | sub execute { | ||||||||||
|
Subroutine
execute: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 39 | 11 | my ($class, $host, $task) = @_; | |||||||||||
| 40 | |||||||||||||
| 41 | 11 | my $result = { host => $host, error => 0 }; | |||||||||||
| 42 | |||||||||||||
| 43 | 11 | local $@; | |||||||||||
| 44 | 11 | eval { $task->execute($host) }; | |||||||||||
| 45 | 11 | ▶ | if ($@) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 46 | 3 | chomp $@; | |||||||||||
| 47 | 3 | log error => sprintf '[%s] %s', $host, $@; | |||||||||||
| 48 | 3 | $result->{error} = 1; | |||||||||||
| 49 | } | ||||||||||||
| 50 | |||||||||||||
| 51 | 11 | return $result; | |||||||||||
| 52 | } | ||||||||||||
| 53 | |||||||||||||
| 54 | 3 | 1; | |||||||||||