lib/Beekeeper/Service/Supervisor/Worker.pm

filter: Statementstmt 10.1% 18 / 178 Branchbran 0.0% 0 / 46 Conditioncond 0.0% 0 / 66 MC/DCmcdc 0.0% 0 / 34 Subroutinesub 20.0% 5 / 25 Podpod 26.6% 4 / 15 totaltotal 7.4% 27 / 364 CC 64 SCAR 40.9
CC
64
Cov
6%
restart_workers
156.0
check_workers
110.0
set_worker_status
56.0
CRAP 59.5
« lib/Beekeeper/WorkerPool/Daemon.pm ↑ Summary lib/Beekeeper/Service/Router/Worker.pm »
1 package Beekeeper::Service::Supervisor::Worker;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = '0.10';
7  
8 1 ▶use Beekeeper::Worker ':log';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use base 'Beekeeper::Worker';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶use Beekeeper::Worker::Extension::SharedCache;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 our $CHECK_PERIOD = $Beekeeper::Worker::REPORT_STATUS_PERIOD;
14  
15  
16 0 ▶sub authorize_request {
Subroutine authorize_request: not called CC=5 SCAR=34.0
Pod documented
17 0 my ($self, $req) = @_;
18  
19 0 ▶ if ($req->{method} eq '_bkpr.supervisor.worker_status' ||
Branch: 1 branch
BranchTrueFalseTotal
if ($req->{'method'} eq '_bkpr.supervisor.worker_status' or $req->{'method'} eq '_bkpr.supervisor.worker_exit') { } 0 0 0
Condition0%0/3
$req->{"method"} eq "_bkpr.supervisor.worker_status" or $req->{"method"} eq "_bkpr.supervisor.worker_exit"
l!l&&r!l&&!r
000
MC/DC0%0/2
$req->{"method"} eq "_bkpr.supervisor.worker_status" or $req->{"method"} eq "_bkpr.supervisor.worker_exit"
$req->{"method"} eq "_bkpr.supervisor.worker_status" $req->{"method"} eq "_bkpr.supervisor.worker_exit"
Truth table0%0/3
A or B
A= $req->{"method"} eq "_bkpr.supervisor.worker_status"B= $req->{"method"} eq "_bkpr.supervisor.worker_exit"
ABresult
1X1
011
000
20 $req->{method} eq '_bkpr.supervisor.worker_exit' ) {
21  
22 0 ▶ return unless $self->__has_authorization_token('BKPR_SYSTEM');
Branch: 1 branch
BranchTrueFalseTotal
unless $self->__has_authorization_token("BKPR_SYSTEM") 0 0 0
23 }
24 else {
25  
26 0 ▶ return unless $self->__has_authorization_token('BKPR_ADMIN');
Branch: 1 branch
BranchTrueFalseTotal
unless $self->__has_authorization_token("BKPR_ADMIN") 0 0 0
27 }
28  
29 0 return BKPR_REQUEST_AUTHORIZED;
30 }
31  
32 0 ▶sub on_startup {
Subroutine on_startup: not called CC=1 SCAR=6.9
Pod documented
33 0 my $self = shift;
34  
35 0 $self->{host} = $self->{_WORKER}->{hostname};
36 0 $self->{pool} = $self->{_WORKER}->{pool_id};
37  
38 0 $self->{Workers} = $self->shared_cache( id => "workers", max_age => $CHECK_PERIOD * 4 );
39 0 $self->{Queues} = {};
40 0 $self->{Load} = {};
41  
42 0 $self->accept_notifications(
43 '_bkpr.supervisor.restart_pool' => 'restart_pool',
44 '_bkpr.supervisor.restart_workers' => 'restart_workers',
45 );
46  
47 0 $self->accept_remote_calls(
48 '_bkpr.supervisor.worker_status' => 'worker_status',
49 '_bkpr.supervisor.worker_exit' => 'worker_exit',
50 '_bkpr.supervisor.get_workers_status' => 'get_workers_status',
51 '_bkpr.supervisor.get_services_status' => 'get_services_status',
52 );
53  
54 $self->{check_status_tmr} = AnyEvent->timer(
55 after => rand($CHECK_PERIOD),
56 interval => $CHECK_PERIOD,
57 0 ▶ cb => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
58 0 $self->check_workers;
59 0 $self->check_queues;
60 },
61 0 );
62 }
63  
64 0 ▶sub on_shutdown {
Subroutine on_shutdown: not called CC=1 SCAR=6.9
Pod documented
65 0 my $self = shift;
66  
67 # Disconnect shared cache
68 0 undef $self->{Workers};
69 }
70  
71 0 ▶sub log_handler {
Subroutine log_handler: not called CC=1 SCAR=6.9
Pod documented
72 0 my $self = shift;
73  
74 # Use pool's logfile
75 0 $self->SUPER::log_handler( foreground => 1 );
76 }
77  
78 0 ▶sub worker_status {
Subroutine worker_status: not called CC=1 SCAR=6.9
Pod undocumented
79 0 my ($self, $params) = @_;
80  
81 0 $self->set_worker_status( %$params );
82 }
83  
84 0 ▶sub worker_exit {
Subroutine worker_exit: not called CC=1 SCAR=6.9
Pod undocumented
85 0 my ($self, $params) = @_;
86  
87 0 $self->remove_worker_status( %$params );
88  
89 # Check for unserviced queues, just in case of worker being the last of its kind
90 0 $self->check_queues;
91 }
92  
93 0 ▶sub set_worker_status {
Subroutine set_worker_status: not called CC=7 SCAR=40.3
Pod undocumented
94 0 my ($self, %args) = @_;
95  
96 0 ▶ my $pool = $args{'pool'} || die;
Condition0%0/2
$args{'pool'} || die()
l!l
00
MC/DC0%0/1
$args{'pool'} || die()
$args{'pool'}
Truth table0%0/2
A
A= $args{'pool'}
Aresult
11
00
97 0 ▶ my $host = $args{'host'} || die;
Condition0%0/2
$args{'host'} || die()
l!l
00
MC/DC0%0/1
$args{'host'} || die()
$args{'host'}
Truth table0%0/2
A
A= $args{'host'}
Aresult
11
00
98 0 ▶ my $pid = $args{'pid'} || die;
Condition0%0/2
$args{'pid'} || die()
l!l
00
MC/DC0%0/1
$args{'pid'} || die()
$args{'pid'}
Truth table0%0/2
A
A= $args{'pid'}
Aresult
11
00
99  
100 0 my $worker_id = "$host:$pool:$pid";
101  
102 0 ▶ my $status = $self->{Workers}->get( $worker_id ) || {};
Condition0%0/2
$self->{'Workers'}->get($worker_id) || {}
l!l
00
MC/DC0%0/1
$self->{'Workers'}->get($worker_id) || {}
$self->{'Workers'}->get($worker_id)
Truth table0%0/2
A
A= $self->{'Workers'}->get($worker_id)
Aresult
11
00
103  
104 0 $status = { %$status, %args };
105  
106 0 $self->{Workers}->set( $worker_id => $status );
107  
108 0 ▶ if ($status->{queue}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($status->{"queue"}) 0 0 0
109 0 $self->{Queues}->{$_} = 1 foreach @{$status->{queue}};
110 }
111 }
112  
113 0 ▶sub touch_worker_status {
Subroutine touch_worker_status: not called CC=4 SCAR=30.0
Pod undocumented
114 0 my ($self, %args) = @_;
115  
116 0 ▶ my $pool = $args{'pool'} || die;
Condition0%0/2
$args{'pool'} || die()
l!l
00
MC/DC0%0/1
$args{'pool'} || die()
$args{'pool'}
Truth table0%0/2
A
A= $args{'pool'}
Aresult
11
00
117 0 ▶ my $host = $args{'host'} || die;
Condition0%0/2
$args{'host'} || die()
l!l
00
MC/DC0%0/1
$args{'host'} || die()
$args{'host'}
Truth table0%0/2
A
A= $args{'host'}
Aresult
11
00
118 0 ▶ my $pid = $args{'pid'} || die;
Condition0%0/2
$args{'pid'} || die()
l!l
00
MC/DC0%0/1
$args{'pid'} || die()
$args{'pid'}
Truth table0%0/2
A
A= $args{'pid'}
Aresult
11
00
119  
120 0 my $worker_id = "$host:$pool:$pid";
121  
122 0 $self->{Workers}->touch( $worker_id );
123 }
124  
125 0 ▶sub remove_worker_status {
Subroutine remove_worker_status: not called CC=4 SCAR=30.0
Pod undocumented
126 0 my ($self, %args) = @_;
127  
128 0 ▶ my $pool = $args{'pool'} || die;
Condition0%0/2
$args{'pool'} || die()
l!l
00
MC/DC0%0/1
$args{'pool'} || die()
$args{'pool'}
Truth table0%0/2
A
A= $args{'pool'}
Aresult
11
00
129 0 ▶ my $host = $args{'host'} || die;
Condition0%0/2
$args{'host'} || die()
l!l
00
MC/DC0%0/1
$args{'host'} || die()
$args{'host'}
Truth table0%0/2
A
A= $args{'host'}
Aresult
11
00
130 0 ▶ my $pid = $args{'pid'} || die;
Condition0%0/2
$args{'pid'} || die()
l!l
00
MC/DC0%0/1
$args{'pid'} || die()
$args{'pid'}
Truth table0%0/2
A
A= $args{'pid'}
Aresult
11
00
131  
132 0 my $worker_id = "$host:$pool:$pid";
133  
134 0 $self->{Workers}->delete( $worker_id );
135 }
136  
137 0 ▶sub _get_workers {
Subroutine _get_workers: not called CC=7 SCAR=40.3
138 0 my ($self, %args) = @_;
139  
140 0 my $host = $args{'host'};
141 0 my $pool = $args{'pool'};
142 0 my $class = $args{'class'};
143  
144 my @workers = grep { defined $_ &&
145 (!$host || $_->{host} eq $host ) &&
146 (!$pool || $_->{pool} eq $pool ) &&
147 0 ▶ (!$class || $_->{class} eq $class)
Condition0%0/18
defined $_ && (!$host || $_->{'host'} eq $host) && (!$pool || $_->{'pool'} eq $pool) && (!$class || $_->{'class'} eq $class)
!ll&&!rl&&r
000
defined $_ and !$host || $_->{"host"} eq $host and !$pool || $_->{"pool"} eq $pool
!ll&&!rl&&r
000
defined $_ and !$host || $_->{"host"} eq $host
!ll&&!rl&&r
000
not $host or $_->{"host"} eq $host
l!l&&r!l&&!r
000
not $pool or $_->{"pool"} eq $pool
l!l&&r!l&&!r
000
not $class or $_->{"class"} eq $class
l!l&&r!l&&!r
000
MC/DC0%0/7
defined $_ && (!$host || $_->{'host'} eq $host) && (!$pool || $_->{'pool'} eq $pool) && (!$class || $_->{'class'} eq $class)
defined $_ not $host $_->{"host"} eq $host not $pool $_->{"pool"} eq $pool not $class $_->{"class"} eq $class
Truth table0%0/16
A and not(B) or C and not(D) or E && not(F) or G
A= defined $_B= not $hostC= $_->{"host"} eq $hostD= not $poolE= $_->{"pool"} eq $poolF= not $classG= $_->{"class"} eq $class
ABCDEFGresult
0XXXXXX0
100XXXX0
11X00XX0
10100XX0
11X1X000
11X01000
1011X000
10101000
11X1X1X1
11X1X011
11X011X1
11X01011
1011X1X1
1011X011
101011X1
10101011
148 0 } values %{$self->{Workers}->{data}};
149  
150 0 return \@workers;
151 }
152  
153  
154 0 ▶sub check_workers {
Subroutine check_workers: not called CC=10 SCAR=47.0
Pod undocumented
155 0 my $self = shift;
156  
157 0 my $local_workers = $self->_get_workers( host => $self->{host} );
158  
159 0 foreach my $worker (@$local_workers) {
160  
161 0 ▶ next unless defined $worker;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $worker 0 0 0
162  
163 0 my $pid = $worker->{pid};
164  
165 0 my ($mem_size, $cpu_ticks);
166  
167 0 ▶ if (open my $fh, '<', "/proc/$pid/statm") {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $fh, '<', "/proc/$pid/statm") { } 0 0 0
168 # Linux on intel x86 has a fixed 4KiB page size
169 0 my ($virt, $res, $share) = map { $_ * 4 } (split /\s/, scalar <$fh>)[0,1,2];
170 0 close $fh;
171  
172 # Apache::SizeLimit uses $virt + $share but that doensn't look useful
173 0 $mem_size = $res - $share;
174 }
175 else {
176 # Worker is not running anymore
177 $self->remove_worker_status(
178 pool => $worker->{pool},
179 host => $worker->{host},
180 pid => $worker->{pid},
181 0 );
182  
183 0 next;
184 }
185  
186 0 ▶ if (open my $fh, '<', "/proc/$pid/stat") {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $fh, "<", "/proc/$pid/stat") 0 0 0
187 0 my ($utime, $stime) = (split /\s/, scalar <$fh>)[13,14];
188 0 close $fh;
189  
190 # Values in clock ticks, usually 100 (getconf CLK_TCK)
191 0 $cpu_ticks = $utime + $stime;
192 }
193  
194 0 ▶ my $cpu_load = sprintf("%.2f",($cpu_ticks - ($self->{Load}->{$pid} || 0)) / $CHECK_PERIOD);
Condition0%0/2
$self->{'Load'}{$pid} || 0
l!l
00
MC/DC0%0/1
$self->{'Load'}{$pid} || 0
$self->{'Load'}{$pid}
Truth table0%0/2
A
A= $self->{'Load'}{$pid}
Aresult
11
00
195 0 $self->{Load}->{$pid} = $cpu_ticks;
196  
197 0 ▶ my $old_msize = $worker->{msize} || 0.01;
Condition0%0/2
$worker->{'msize'} || 0.01
l!l
00
MC/DC0%0/1
$worker->{'msize'} || 0.01
$worker->{'msize'}
Truth table0%0/2
A
A= $worker->{'msize'}
Aresult
11
00
198 0 ▶ my $old_load = $worker->{cpu} || 0.01;
Condition0%0/2
$worker->{'cpu'} || 0.01
l!l
00
MC/DC0%0/1
$worker->{'cpu'} || 0.01
$worker->{'cpu'}
Truth table0%0/2
A
A= $worker->{'cpu'}
Aresult
11
00
199  
200 0 ▶ if (( abs($mem_size - $old_msize) / $old_msize < .05 ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (abs($mem_size - $old_msize) / $old_msize < 0.05 and abs($cpu_load - $old_load) / $old_load < 0.05) { } 0 0 0
Condition0%0/3
abs($mem_size - $old_msize) / $old_msize < "0.05" and abs($cpu_load - $old_load) / $old_load < "0.05"
!ll&&!rl&&r
000
MC/DC0%0/2
abs($mem_size - $old_msize) / $old_msize < "0.05" and abs($cpu_load - $old_load) / $old_load < "0.05"
abs($mem_size - $old_msize) / $old_msize < "0.05" abs($cpu_load - $old_load) / $old_load < "0.05"
Truth table0%0/3
A and B
A= abs($mem_size - $old_msize) / $old_msize < "0.05"B= abs($cpu_load - $old_load) / $old_load < "0.05"
ABresult
0X0
100
111
201 ( abs($cpu_load - $old_load) / $old_load < .05 )) {
202  
203 # Avoid sending messages when changes are below 5%
204 $self->touch_worker_status(
205 pool => $worker->{pool},
206 host => $worker->{host},
207 pid => $worker->{pid},
208 0 );
209 }
210 else {
211 # Update worker memory usage and cpu load
212 $self->set_worker_status(
213 pool => $worker->{pool},
214 host => $worker->{host},
215 pid => $worker->{pid},
216 0 mem => $mem_size,
217 cpu => $cpu_load,
218 );
219 }
220 }
221 }
222  
223  
224 0 ▶sub check_queues {
Subroutine check_queues: not called CC=7 SCAR=40.3
Pod undocumented
225 0 my $self = shift;
226  
227 0 my $Queues = $self->{Queues};
228  
229 0 $Queues->{$_} = 0 foreach (keys %$Queues);
230  
231 # Count how many workers are servicing each queue
232 0 foreach my $worker (values %{$self->{Workers}->{data}}) {
233
234 # Skip defunct workers (which are remembered a while)
235 0 ▶ next unless defined $worker;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $worker 0 0 0
236  
237 # Do not count queues being drained by Sinkhole
238 0 ▶ next if ($worker->{class} eq 'Beekeeper::Service::Sinkhole::Worker');
Branch: 1 branch
BranchTrueFalseTotal
if $worker->{"class"} eq "Beekeeper::Service::Sinkhole::Worker" 0 0 0
239  
240 0 $Queues->{$_}++ foreach @{$worker->{queue}};
241 }
242  
243 0 my @unserviced = grep { $Queues->{$_} == 0 } keys %$Queues;
244  
245 0 ▶ return unless @unserviced;
Branch: 1 branch
BranchTrueFalseTotal
unless @unserviced 0 0 0
246  
247 # Tell Sinkhole to respond immediately to all requests sent to
248 # unserviced queues with a "Method not available" error response
249  
250 0 my $guard = $self->__use_authorization_token('BKPR_SYSTEM');
251  
252 0 $self->send_notification(
253 method => '_bkpr.sinkhole.unserviced_queues',
254 params => { queues => \@unserviced },
255 );
256 }
257  
258  
259 0 ▶sub get_workers_status {
Subroutine get_workers_status: not called CC=1 SCAR=6.9
Pod undocumented
260 0 my ($self, $args) = @_;
261  
262 my $workers = $self->_get_workers(
263 host => $args->{host},
264 pool => $args->{pool},
265 class => $args->{class},
266 0 );
267  
268 0 return $workers;
269 }
270  
271  
272 0 ▶sub get_services_status {
Subroutine get_services_status: not called CC=6 SCAR=37.4
Pod undocumented
273 0 my ($self, $args) = @_;
274  
275 my $workers = $self->_get_workers(
276 host => $args->{host},
277 pool => $args->{pool},
278 class => $args->{class},
279 0 );
280  
281 0 my %services;
282  
283 0 foreach my $worker (@$workers) {
284 0 $services{$worker->{class}}{count}++;
285 0 $services{$worker->{class}}{cps} += $worker->{cps};
286 0 $services{$worker->{class}}{nps} += $worker->{nps};
287 0 $services{$worker->{class}}{err} += $worker->{err};
288 0 ▶ $services{$worker->{class}}{cpu} += $worker->{cpu} || 0;
Condition0%0/2
$worker->{'cpu'} || 0
l!l
00
MC/DC0%0/1
$worker->{'cpu'} || 0
$worker->{'cpu'}
Truth table0%0/2
A
A= $worker->{'cpu'}
Aresult
11
00
289 0 ▶ $services{$worker->{class}}{mem} += $worker->{mem} || 0;
Condition0%0/2
$worker->{'mem'} || 0
l!l
00
MC/DC0%0/1
$worker->{'mem'} || 0
$worker->{'mem'}
Truth table0%0/2
A
A= $worker->{'mem'}
Aresult
11
00
290 0 $services{$worker->{class}}{load} += $worker->{load};
291 }
292  
293 0 foreach my $service (values %services) {
294 0 $service->{load} = $service->{load} / $service->{count};
295 }
296  
297 0 foreach my $service (values %services) {
298 0 $service->{cps} = sprintf("%.2f", $service->{cps} );
299 0 $service->{nps} = sprintf("%.2f", $service->{nps} );
300 0 $service->{err} = sprintf("%.2f", $service->{err} );
301 0 $service->{cpu} = sprintf("%.2f", $service->{cpu} );
302 0 $service->{mem} = sprintf("%.2f", $service->{mem} );
303 0 $service->{load} = sprintf("%.2f", $service->{load});
304 }
305  
306 0 return \%services;
307 }
308  
309  
310 0 ▶sub restart_workers {
Subroutine restart_workers: not called CC=12 SCAR=50.5
Pod undocumented
311 0 my ($self, $args) = @_;
312  
313 0 ▶ return if ($args->{host} && $args->{host} ne $self->{host});
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"host"} and $args->{"host"} ne $self->{"host"} 0 0 0
Condition0%0/3
$args->{"host"} and $args->{"host"} ne $self->{"host"}
!ll&&!rl&&r
000
MC/DC0%0/2
$args->{"host"} and $args->{"host"} ne $self->{"host"}
$args->{"host"} $args->{"host"} ne $self->{"host"}
Truth table0%0/3
A and B
A= $args->{"host"}B= $args->{"host"} ne $self->{"host"}
ABresult
0X0
100
111
314 0 ▶ return if ($args->{pool} && $args->{pool} ne $self->{pool});
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"pool"} and $args->{"pool"} ne $self->{"pool"} 0 0 0
Condition0%0/3
$args->{"pool"} and $args->{"pool"} ne $self->{"pool"}
!ll&&!rl&&r
000
MC/DC0%0/2
$args->{"pool"} and $args->{"pool"} ne $self->{"pool"}
$args->{"pool"} $args->{"pool"} ne $self->{"pool"}
Truth table0%0/3
A and B
A= $args->{"pool"}B= $args->{"pool"} ne $self->{"pool"}
ABresult
0X0
100
111
315  
316 my $workers = $self->_get_workers(
317 host => $self->{host},
318 pool => $self->{pool},
319 class => $args->{class},
320 0 );
321  
322 0 ▶ log_info "Restarting workers" . ($args->{class} ? " $args->{class}..." : "...");
Branch: 1 branch
BranchTrueFalseTotal
$args->{'class'} ? : 0 0 0
323  
324 0 my @worker_pids;
325  
326 0 foreach my $worker (@$workers) {
327 # Do not restart supervisor
328 0 ▶ next if ($worker->{class} eq 'Beekeeper::Service::Supervisor::Worker');
Branch: 1 branch
BranchTrueFalseTotal
if $worker->{"class"} eq "Beekeeper::Service::Supervisor::Worker" 0 0 0
329  
330 0 my ($pid) = ($worker->{pid} =~ m/^(\d+)$/); # untaint
331 0 ▶ push @worker_pids, $pid if ($pid);
Branch: 1 branch
BranchTrueFalseTotal
if $pid 0 0 0
332 }
333  
334 0 ▶ if (!$args->{delay}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $args->{'delay'}) { } 0 0 0
335 # Restart all workers at once
336 0 foreach my $pid (@worker_pids) {
337 0 kill( 'TERM', $pid );
338 }
339 }
340 else {
341 # Slowly restart all workers
342 0 my $delay = $args->{delay};
343 0 my $count = 0;
344  
345 0 foreach my $pid (@worker_pids) {
346 $self->{restart_worker_tmr}->{$pid} = AnyEvent->timer(
347 after => $delay * $count++,
348 0 ▶ cb => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
349 0 delete $self->{restart_worker_tmr}->{$pid};
350 0 kill( 'TERM', $pid );
351 },
352 0 );
353 }
354 }
355 }
356  
357  
358 0 ▶sub restart_pool {
Subroutine restart_pool: not called CC=6 SCAR=37.4
Pod undocumented
359 0 my ($self, $args) = @_;
360  
361 0 ▶ return if ($args->{host} && $args->{host} ne $self->{host});
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"host"} and $args->{"host"} ne $self->{"host"} 0 0 0
Condition0%0/3
$args->{"host"} and $args->{"host"} ne $self->{"host"}
!ll&&!rl&&r
000
MC/DC0%0/2
$args->{"host"} and $args->{"host"} ne $self->{"host"}
$args->{"host"} $args->{"host"} ne $self->{"host"}
Truth table0%0/3
A and B
A= $args->{"host"}B= $args->{"host"} ne $self->{"host"}
ABresult
0X0
100
111
362 0 ▶ return if ($args->{pool} && $args->{pool} ne $self->{pool});
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"pool"} and $args->{"pool"} ne $self->{"pool"} 0 0 0
Condition0%0/3
$args->{"pool"} and $args->{"pool"} ne $self->{"pool"}
!ll&&!rl&&r
000
MC/DC0%0/2
$args->{"pool"} and $args->{"pool"} ne $self->{"pool"}
$args->{"pool"} $args->{"pool"} ne $self->{"pool"}
Truth table0%0/3
A and B
A= $args->{"pool"}B= $args->{"pool"} ne $self->{"pool"}
ABresult
0X0
100
111
363  
364 0 my $wpool_pid = $self->{_WORKER}->{parent_pid};
365 0 my $delay = $args->{delay};
366  
367 0 ▶ if (!$delay) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $delay) { } 0 0 0
368 0 kill( 'HUP', $wpool_pid );
369 }
370 else {
371  
372 0 my $index = $self->_get_pool_index( $self->{host}, $self->{pool} );
373  
374 $self->{restart_pool_tmr} = AnyEvent->timer(
375 after => $delay * $index,
376 0 ▶ cb => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
377 0 delete $self->{restart_pool_tmr};
378 0 kill( 'HUP', $wpool_pid );
379 },
380 0 );
381 }
382 }
383  
384 0 ▶sub _get_pool_index {
Subroutine _get_pool_index: not called CC=6 SCAR=37.4
385 0 my ($self, $host, $pool) = @_;
386  
387 # Sort all pools by name, then return the index of the requested one.
388 # Used by restart_pool() to determine restart order across hosts
389  
390 0 my %pools;
391  
392 0 foreach my $worker (values %{$self->{Workers}->{data}}) {
393 0 ▶ next unless defined $worker;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $worker 0 0 0
394 0 $pools{"$worker->{host}:$worker->{pool}"} = 1;
395 }
396  
397 0 ▶ return 0 unless $pools{"$host:$pool"};
Branch: 1 branch
BranchTrueFalseTotal
unless $pools{"${host}:$pool"} 0 0 0
398  
399 0 my $index = 0;
400  
401 0 foreach my $key (sort keys %pools) {
402 0 ▶ last if ($key eq "$host:$pool");
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "${host}:$pool" 0 0 0
403 0 $index++;
404 }
405  
406 0 return $index;
407 }
408  
409 1 1;
410  
411 __END__
« lib/Beekeeper/WorkerPool/Daemon.pm ↑ Summary lib/Beekeeper/Service/Router/Worker.pm »