File Coverage

blib/lib/Search/Elasticsearch/Transport/Async/Simple.pm
Criterion Covered Total %
statement 15 44 34.0
branch 0 8 0.0
condition n/a
subroutine 5 7 71.4
pod 0 1 0.0
total 20 60 33.3


line stmt bran cond sub pod time code
1             package Search::Elasticsearch::Transport::Async::Simple;
2              
3 1     1   27444 use Moo;
  1         18250  
  1         7  
4              
5 1     1   2932 use Time::HiRes qw(time);
  1         2155  
  1         5  
6              
7 1     1   939 use Search::Elasticsearch::Role::Is_Async::Loader ();
  1         3  
  1         23  
8 1     1   921 use Search::Elasticsearch::Util qw(upgrade_error);
  1         29007  
  1         8  
9              
10 1     1   238 use namespace::clean;
  1         3  
  1         8  
11              
12             with 'Search::Elasticsearch::Role::Transport',
13             'Search::Elasticsearch::Role::Is_Async';
14              
15              
16             sub perform_request {
17 0     0 0   my $self = shift();
18 0           my $cb = pop();
19              
20 0           my $pars = $self->tidy_request(@_);
21 0           my $pool = $self->cxn_pool;
22 0           my $log = $self->logger;
23              
24             $pool->next_cxn(sub {
25 0 0   0     unless (@_) {
26 0           $log->error($@);
27 0           $cb->();
28              
29 0           return;
30             }
31              
32 0           my $cxn = $_[0];
33 0           my $ts = time();
34              
35 0           $log->trace_request($cxn, $pars);
36             $cxn->perform_request($pars, sub {
37 0 0         if (@_) {
38 0           my ($code, $res) = @_;
39              
40 0           $pool->request_ok($cxn);
41 0           $log->trace_response($cxn, $code, $res, time() - $ts);
42 0           $cb->($res);
43             }
44             else {
45 0           my $err = upgrade_error($@, {request => $pars});
46              
47 0 0         if ($pool->request_failed($cxn, $err)) {
48 0           $log->debugf('[%s] %s', $cxn->stringify(), "$err");
49 0           $log->info('Retrying request on a new cxn');
50              
51 0           return $self->perform_request($pars, $cb);
52             }
53              
54 0           $log->trace_error($cxn, $err);
55 0           delete($err->{vars}{body});
56 0 0         $err->is('NoNodes')
57             ? $log->critical($err)
58             : $log->error($err);
59              
60 0           $cb->();
61             }
62 0           });
63 0           });
64              
65 0           return;
66             }
67              
68              
69             1;
70              
71              
72             __END__