Re: [dancer-users] dancer-users Digest, Vol 34, Issue 3
config.yml:
ElasticSearch: servers: "10.10.10.33:9200" transport: "httplite" max_requests: 10000 trace_calls: 0 no_refresh: 0 lib/App.pm: use lib "$Bin/../lib"; use App::A; use App::B; lib/App/A.pm: use Dancer ':syntax'; use ElasticSearch; my $elsearch = ElasticSearch->new( config->{ElasticSearch} ); prefix '/a'; get '/config' => sub { return Dumper $elsearch }; lib/App/B.pm: use Dancer ':syntax'; use ElasticSearch; my $elsearch = ElasticSearch->new( config->{ElasticSearch} ); prefix '/b'; get '/config' => sub { return Dumper $elsearch };
Then `get http://localhost:3000/a/config` show that servers: " 10.10.10.33:9200" but `get http://localhost:3000/b/config` show that servers: "127.0.0.1:9200" which is the default setting of ElasticSearch module. 2012/12/10 <dancer-users-request@dancer.pm>
Send dancer-users mailing list submissions to dancer-users@dancer.pm
To subscribe or unsubscribe via the World Wide Web, visit http://lists.preshweb.co.uk/mailman/listinfo/dancer-users or, via email, send a message with subject or body 'help' to dancer-users-request@dancer.pm
You can reach the person managing the list at dancer-users-owner@dancer.pm
When replying, please edit your Subject line so it is more specific than "Re: Contents of dancer-users digest..."
Today's Topics:
1. Can I write own config in config.yml? (chenlin rao) 2. Re: Can I write own config in config.yml? (David Precious) 3. Re: Can I write own config in config.yml? (David Precious)
----------------------------------------------------------------------
Message: 1 Date: Mon, 10 Dec 2012 16:56:46 +0800 From: chenlin rao <rao.chenlin@gmail.com> Subject: [dancer-users] Can I write own config in config.yml? To: dancer-users@perldancer.org Message-ID: <CABwsoohczVCJwVxZcFUqPaS2KdxsK8-rE-V0= TeJEmDEPr4r5w@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1"
I try to write my own elasticsearch config in config.yml:
ElasticSearch: servers: "10.10.10.33:9200" transport: "httplite" max_requests: 10000 trace_calls: 0 no_refresh: 0
But after I got the right `config->{ElasticSearch}` in my lib/DancerApp/A.pm, I got `config->{ElasticSearch}` in my lib/DancerApp/B.pm returns only one line as 'trace_calls:0'.
I try to got config->{appdir} at multi sub and got right result everywhere.
Why??
On Mon, 10 Dec 2012 22:45:39 +0800 chenlin rao <rao.chenlin@gmail.com> wrote:
Then `get http://localhost:3000/a/config` show that servers: " 10.10.10.33:9200" but `get http://localhost:3000/b/config` show that servers: "127.0.0.1:9200" which is the default setting of ElasticSearch module.
Ah - it's a bug in the ElasticSearch module - it modifies the params hashref it gets passed (as it gets a reference, it's modifying what you gave it). In ElasticSearch->new, it passes the params hashref to ElasticSearch::Transport->new, which includes the following: my $servers = delete $params->{servers} || '127.0.0.1:' . $transport_class->default_port; [...] for (qw(timeout max_requests no_refresh deflate max_content_length)) { next unless exists $params->{$_}; $self->$_( delete $params->{$_} ); } Until this problem in ES is fixed, you'll want to take a copy/clone of the config settings before giving them to ElasticSearch. A simple way would be e.g.: my $elsearch = ElasticSearch->new( { %{ config->{ElasticSearch} } } ); -- David Precious ("bigpresh") <davidp@preshweb.co.uk> http://www.preshweb.co.uk/ www.preshweb.co.uk/twitter www.preshweb.co.uk/linkedin www.preshweb.co.uk/facebook www.preshweb.co.uk/cpan www.preshweb.co.uk/github
On Mon, 10 Dec 2012 15:00:48 +0000 David Precious <davidp@preshweb.co.uk> wrote:
Ah - it's a bug in the ElasticSearch module - it modifies the params hashref it gets passed (as it gets a reference, it's modifying what you gave it). [...] Until this problem in ES is fixed, you'll want to take a copy/clone of the config settings before giving them to ElasticSearch.
I should probably add that I've reported the issue to the author of the ElasticSearch module: https://github.com/clintongormley/ElasticSearch.pm/issues/34 -- David Precious ("bigpresh") <davidp@preshweb.co.uk> http://www.preshweb.co.uk/ www.preshweb.co.uk/twitter www.preshweb.co.uk/linkedin www.preshweb.co.uk/facebook www.preshweb.co.uk/cpan www.preshweb.co.uk/github
participants (2)
-
chenlin rao -
David Precious