File Coverage

blib/lib/Search/Elasticsearch/Role/Cxn/Async.pm
Criterion Covered Total %
statement 24 24 100.0
branch n/a
condition n/a
subroutine 9 9 100.0
pod 2 2 100.0
total 35 35 100.0


line stmt bran cond sub pod time code
1             # Licensed to Elasticsearch B.V. under one or more contributor
2             # license agreements. See the NOTICE file distributed with
3             # this work for additional information regarding copyright
4             # ownership. Elasticsearch B.V. licenses this file to you under
5             # the Apache License, Version 2.0 (the "License"); you may
6             # not use this file except in compliance with the License.
7             # You may obtain a copy of the License at
8             #
9             # http://www.apache.org/licenses/LICENSE-2.0
10             #
11             # Unless required by applicable law or agreed to in writing,
12             # software distributed under the License is distributed on an
13             # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14             # KIND, either express or implied. See the License for the
15             # specific language governing permissions and limitations
16             # under the License.
17              
18             package Search::Elasticsearch::Role::Cxn::Async;
19             $Search::Elasticsearch::Role::Cxn::Async::VERSION = '8.00';
20 50     50   4481915 use Moo::Role;
  50         351  
  50         402  
21              
22 50     50   20235 use Search::Elasticsearch::Util qw(new_error);
  50         171  
  50         415  
23 50     50   12822 use namespace::clean;
  50         138  
  50         399  
24              
25             #===================================
26             sub pings_ok {
27             #===================================
28 47     47 1 97 my $self = shift;
29 47         178 $self->logger->infof( 'Pinging [%s]', $self->stringify );
30              
31             $self->perform_request(
32             { method => 'HEAD',
33             path => '/',
34             timeout => $self->ping_timeout,
35             }
36             )->then(
37             sub {
38 33     33   9607 $self->logger->infof( 'Marking [%s] as live', $self->stringify );
39 33         1898 $self->mark_live;
40             },
41             sub {
42 14     14   5942 $self->logger->debug(@_);
43 14         451 $self->mark_dead;
44 14         1574 die(@_);
45             }
46 47         3973 );
47             }
48              
49             #===================================
50             sub sniff {
51             #===================================
52 54     54 1 129 my $self = shift;
53 54         231 $self->logger->infof( 'Sniffing [%s]', $self->stringify );
54             $self->perform_request(
55             { method => 'GET',
56             path => '/_nodes/http',
57             qs => { timeout => $self->sniff_timeout . 's' },
58             timeout => $self->sniff_request_timeout,
59             }
60             )->then(
61 41     41   20944 sub { ( $self, $_[1]->{nodes} ) },
62             sub {
63 13     13   6345 $self->mark_dead;
64 13         1640 $self->logger->debug(@_);
65 13         368 ($self);
66             }
67 54         4458 );
68             }
69             1;
70              
71             # ABSTRACT: Provides common functionality to async Cxn implementations
72              
73             __END__