Transport/Async.pm

filter: Statementstmt 89.1% 41 / 46 Branchbran 100% 6 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 83.3% 10 / 12 Podpod 100% 1 / 1 totaltotal 89.2% 58 / 65 CC 4 SCAR 6.6
CC
4
Cov
90%
__ANON__
4.0
__ANON__
2.0
__ANON__
2.0
CRAP 1.9
« Client/6_0/Async.pm ↑ Summary Async.pm »
1 package Search::Elasticsearch::Transport::Async;
2 50 $Search::Elasticsearch::Transport::Async::VERSION = '6.80';
3 50 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 50 with 'Search::Elasticsearch::Role::Is_Async',
5 'Search::Elasticsearch::Role::Transport';
6  
7 50 ▶use Time::HiRes qw(time);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 50 ▶use Search::Elasticsearch::Util qw(upgrade_error);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 50 ▶use Promises qw(deferred);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 50 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 #===================================
13 sub perform_request {
14 #===================================
15 32 ▶ my $self = shift;
Subroutine perform_request: called CC=1 SCAR=0.0
Pod documented
16 32 my $params = $self->tidy_request(@_);
17 32 my $pool = $self->cxn_pool;
18 32 my $logger = $self->logger;
19  
20 32 my $deferred = deferred;
21  
22 32 my ( $start, $cxn );
23 $pool->next_cxn
24  
25 # perform request
26 ->then(
27 sub {
28 9 ▶ $cxn = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
29 9 $start = time();
30 9 $cxn->perform_request($params);
31 }
32 )
33  
34 # log request regardless of success/failure
35 32 ▶ ->finally( sub { $logger->trace_request( $cxn, $params ) } )
Subroutine __ANON__: called CC=1 SCAR=0.0
36  
37 ->done(
38 # request succeeded
39 sub {
40 0 ▶ my ( $code, $response ) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
41 0 $pool->request_ok($cxn);
42 0 $logger->trace_response( $cxn, $code, $response,
43 time() - $start );
44 0 $deferred->resolve($response);
45 },
46  
47 # request failed
48 sub {
49 32 ▶ my $error = upgrade_error( shift(), { request => $params } );
Subroutine __ANON__: called CC=4 SCAR=13.9
50 32 ▶ if ( $pool->request_failed( $cxn, $error ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pool->request_failed($cxn, $error)) 2 30 32
51  
52 # log failed, then retry
53 2 $logger->debugf( "[%s] %s", $cxn->stringify, "$error" );
54 2 $logger->info('Retrying request on a new cxn');
55 return $self->perform_request($params)->done(
56 0 ▶ sub { $deferred->resolve(@_) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
57 2 ▶ sub { $deferred->reject(@_) }
Subroutine __ANON__: called CC=1 SCAR=0.0
58 2 );
59 }
60 30 ▶ if ($cxn) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cxn) 7 23 30
61 7 $logger->trace_request( $cxn, $params );
62 7 $logger->trace_error( $cxn, $error );
63 }
64 30 ▶ $error->is('NoNodes')
Branch: 1 branch
BranchTrueFalseTotal
$error->is('NoNodes') ? : 23 7 30
65 ? $logger->critical($error)
66 : $logger->error($error);
67 30 $deferred->reject($error);
68 }
69 32 );
70 32 return $deferred->promise;
71 }
72  
73 50 1;
74  
75 #ABSTRACT: Provides async interface between the client class and the Elasticsearch cluster
76  
77 __END__
« Client/6_0/Async.pm ↑ Summary Async.pm »