Skip to content

Commit 33c1b14

Browse files
authored
Merge pull request #65 from metacpan/mickey/conf
ES / conf - support different node modes
2 parents ee47046 + 4d57613 commit 33c1b14

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

lib/MetaCPAN/ES.pm

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,23 @@ use Search::Elasticsearch;
1010
use MetaCPAN::Ingest qw< config handle_error >;
1111

1212
sub new ( $class, %args ) {
13+
my $mode = $args{mode} // "local";
1314
my $node = $args{node};
1415
my $index = $args{index} // "cpan";
1516

1617
my $config = config;
17-
$node ||= $config->{es_node};
18-
$node or die "Cannot create an ES instance without a node\n";
18+
my $config_node =
19+
$node ? $node :
20+
$mode eq 'local' ? $config->{es_node} :
21+
$mode eq 'test' ? $config->{es_test_node} :
22+
$mode eq 'prod' ? $config->{es_production_node} :
23+
undef;
24+
$config_node or die "Cannot create an ES instance without a node\n";
1925

2026
return bless {
2127
es => Search::Elasticsearch->new(
2228
client => '2_0::Direct',
23-
nodes => [$node],
29+
nodes => [$config_node],
2430
),
2531
index => $index,
2632
( $args{type} ? ( type => $args{type} ) : () ),

metacpan_ingest.conf

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ log4perl_file log4perl.conf
44

55
es_node "elasticsearch:9200"
66

7-
# Dev: for testing -
7+
# for local data tests
8+
es_test_node "elasticsearch_test:9200"
9+
810
# to enable *reading* from profuction (check it's used in the code):
9-
es_test_node "https://fastapi.metacpan.org/v1"
11+
es_production_node "https://fastapi.metacpan.org/v1"

0 commit comments

Comments
 (0)