File Coverage

blib/lib/Search/Elasticsearch/CxnPool/Async/Simple/Static.pm
Criterion Covered Total %
statement 12 37 32.4
branch 0 12 0.0
condition 0 3 0.0
subroutine 4 6 66.6
pod 0 1 0.0
total 16 59 27.1


line stmt bran cond sub pod time code
1             package Search::Elasticsearch::CxnPool::Async::Simple::Static;
2              
3 1     1   23797 use Moo;
  1         24804  
  1         6  
4              
5 1     1   2525 use Search::Elasticsearch::Role::Is_Async::Loader ();
  1         3  
  1         23  
6 1     1   1048 use Search::Elasticsearch::Util qw(new_error);
  1         30984  
  1         7  
7              
8 1     1   199 use namespace::clean;
  1         2  
  1         8  
9              
10             with 'Search::Elasticsearch::Role::CxnPool::Static',
11             'Search::Elasticsearch::Role::Is_Async';
12              
13              
14             sub next_cxn {
15 0     0 0   my ($self, $cb) = @_;
16              
17 0           my $cxns = $self->cxns;
18 0           my (%seen, @skip);
19              
20 0           my $sub; $sub = sub {
21 0     0     my $cnt = @$cxns;
22 0           my $fnd;
23              
24 0 0         if ($cnt > keys(%seen)) {
25 0           while ($cnt--) {
26 0           my $cxn = $cxns->[$self->next_cxn_num];
27              
28 0 0         next if $seen{$cxn}++;
29              
30 0 0         return $cb->($cxn) if $cxn->is_live;
31              
32 0 0         if ($cxn->next_ping <= time()) {
33 0           $fnd = $cxn;
34 0           last;
35             }
36 0           push(@skip, $cxn);
37             }
38             }
39              
40 0 0 0       if ($fnd ||= shift(@skip)) {
41             return $fnd->pings_ok(sub {
42 0 0         return $cb->($fnd) if $_[0];
43 0           $sub->();
44 0           });
45             }
46              
47 0           $_->force_ping() for @$cxns;
48              
49 0           local $@ = new_error('NoNodes', 'No nodes are available: [' . $self->cxns_str . ']');
50              
51 0           $cb->();
52 0           };
53              
54 0           $sub->();
55              
56 0           return;
57             }
58              
59              
60             1;
61              
62              
63             __END__