Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always use type coercion to construct Search::Elasticsearch object #1298

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/MetaCPAN/Script/Snapshot.pm
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ has snap_name => (
has host => (
is => 'ro',
isa => Str,
default =>
sub { MetaCPAN::Server::Config::config()->{elasticsearch_servers} },
default => sub {
my $self = shift;
return $self->es->transport->cxn_pool->cxns->[0]->uri;
},
documentation => 'ES host, defaults to: http://localhost:9200',
);

Expand Down
4 changes: 3 additions & 1 deletion metacpan_server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ git: /usr/bin/git
cpan: /CPAN
secret: "the stone roses"
level: info
elasticsearch_servers: http://elasticsearch:9200
elasticsearch_servers:
client: '2_0::Direct'
nodes: http://elasticsearch:9200
minion_dsn: "postgresql://metacpan:t00lchain@pghost:5432/minion_queue"
port: 5000

Expand Down
4 changes: 3 additions & 1 deletion metacpan_server_testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ level: warn
port: 5000
source_base: var/t/tmp/source

elasticsearch_servers: http://elasticsearch_test:9200
elasticsearch_servers:
client: '2_0::Direct'
nodes: http://elasticsearch_test:9200

logger:
class: Log::Log4perl::Appender::Screen
Expand Down
3 changes: 1 addition & 2 deletions t/lib/MetaCPAN/Server/Test.pm
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ sub app {

sub model {
my $c = MetaCPAN::Server::Config::config();
MetaCPAN::Model->new(
es => { nodes => [ $c->{elasticsearch_servers} ] } );
MetaCPAN::Model->new( es => $c->{elasticsearch_servers} );
}

1;
Expand Down
13 changes: 7 additions & 6 deletions t/lib/MetaCPAN/TestServer.pm
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ use MetaCPAN::Server ();
use MetaCPAN::Server::Config ();
use MetaCPAN::TestHelpers qw( fakecpan_dir );
use MetaCPAN::Types::TypeTiny qw( HashRef Path );
use MooseX::Types::ElasticSearch qw( ES );
use Search::Elasticsearch ();
use Test::More;

has es_client => (
is => 'ro',
does => 'Search::Elasticsearch::Role::Client',
isa => ES,
coerce => 1,
lazy => 1,
builder => '_build_es_client',
);
Expand Down Expand Up @@ -64,14 +66,13 @@ sub _build_config {
sub _build_es_client {
my $self = shift;

my $es = Search::Elasticsearch->new(
nodes => MetaCPAN::Server::Config::config()->{elasticsearch_servers},
( $ENV{ES_TRACE} ? ( trace_to => [ 'File', 'es.log' ] ) : () )
);
my $es = ES->coerce(
MetaCPAN::Server::Config::config()->{elasticsearch_servers}, );

ok( $es, 'got ElasticSearch object' );
ok( $es, 'got Search::Elasticsearch object' );

note( Test::More::explain( { 'Elasticsearch info' => $es->info } ) );

return $es;
}

Expand Down