File Coverage

blib/lib/Search/Elasticsearch/CxnPool/Async/Simple/Static/NoPing.pm
Criterion Covered Total %
statement 12 27 44.4
branch 0 6 0.0
condition 0 6 0.0
subroutine 4 5 80.0
pod 0 1 0.0
total 16 45 35.5


line stmt bran cond sub pod time code
1             package Search::Elasticsearch::CxnPool::Async::Simple::Static::NoPing;
2              
3 1     1   27463 use Moo;
  1         19848  
  1         7  
4              
5 1     1   8840 use Search::Elasticsearch::Role::Is_Async::Loader ();
  1         3  
  1         28  
6 1     1   1112 use Search::Elasticsearch::Util qw(new_error);
  1         33592  
  1         9  
7              
8 1     1   240 use namespace::clean;
  1         3  
  1         7  
9              
10             with 'Search::Elasticsearch::Role::CxnPool::Static::NoPing',
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 $cnt = @$cxns;
19 0           my $dead = $self->_dead_cxns;
20              
21 0           while ($cnt--) {
22 0           my $cxn = $cxns->[$self->next_cxn_num];
23              
24 0 0 0       return $cb->($cxn) if $cxn->is_live || $cxn->next_ping < time();
25              
26 0 0         push(@$dead, $cxn) unless grep { $_ eq $cxn } @$dead;
  0            
27             }
28              
29 0 0 0       if (@$dead && $self->retries <= $self->max_retries) {
30 0           $_->force_ping for @$dead;
31              
32 0           return $cb->(shift(@$dead));
33             }
34              
35 0           local $@ = new_error('NoNodes', 'No nodes are available: [' . $self->cxns_str . ']');
36              
37 0           $cb->();
38              
39 0           return;
40             }
41              
42              
43             1;
44              
45              
46             __END__