Skip to content

Commit 9c378c5

Browse files
bors[bot]sunny
andauthored
Merge #53
53: Add timeout and max_retries options r=CaroFG a=sunny Add access to `timeout` and `max_retries` configuration options from Meilisearch’s HTTParty integration. Co-authored-by: Sunny Ripert <[email protected]>
2 parents 61ad52d + 3584e81 commit 9c378c5

File tree

4 files changed

+83
-6
lines changed

4 files changed

+83
-6
lines changed

README.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ Create a new file `config/initializers/meilisearch.rb` to setup your `MEILISEARC
104104

105105
```ruby
106106
MeiliSearch.configuration = {
107-
meilisearch_host: 'YourMeiliSearchHost',
108-
meilisearch_api_key: 'YourMeiliSearchAPIKey',
107+
meilisearch_host: 'YourMeiliSearchHost',
108+
meilisearch_api_key: 'YourMeiliSearchAPIKey',
109109
}
110110
```
111111

@@ -183,7 +183,21 @@ The **number of hits per page defaults to 20**, you can customize it by adding t
183183
Book.search('harry potter', hitsPerPage: 10)
184184
```
185185

186-
## ⚙️ Settings
186+
#### Extra Configuration <!-- omit in toc -->
187+
188+
Requests made to MeiliSearch may timeout and retry. To adapt the behavior to
189+
your needs, you can change the parameters during configuration:
190+
191+
```ruby
192+
MeiliSearch.configuration = {
193+
meilisearch_host: 'YourMeiliSearchHost',
194+
meilisearch_api_key: 'YourMeiliSearchAPIKey',
195+
timeout: 2,
196+
max_retries: 1,
197+
}
198+
```
199+
200+
## ⚙️ Settings
187201

188202
You can configure the index settings by adding them inside the `meilisearch` block as shown below:
189203

lib/meilisearch/configuration.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ def configuration=(configuration)
99
end
1010

1111
def client
12-
::MeiliSearch::Client.new(@@configuration[:meilisearch_host], @@configuration[:meilisearch_api_key])
12+
::MeiliSearch::Client.new(
13+
configuration[:meilisearch_host],
14+
configuration[:meilisearch_api_key],
15+
configuration.slice(:timeout, :max_retries)
16+
)
1317
end
1418
end
1519
end

meilisearch-rails.gemspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ Gem::Specification.new do |s|
4141
s.licenses = ["MIT"]
4242
s.require_paths = ["lib"]
4343
s.summary = "MeiliSearch integration for Ruby on Rails."
44-
s.add_dependency(%q<json>, [">= 1.5.1"])
45-
s.add_dependency(%q<meilisearch>, [">= 0.15.3"])
44+
s.add_dependency("json", [">= 1.5.1"])
45+
s.add_dependency("meilisearch", [">= 0.15.4"])
4646
end

spec/configuration_spec.rb

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
require File.expand_path(File.join(__dir__, "spec_helper"))
2+
3+
MeiliSearch.configuration = {
4+
meilisearch_host: ENV['MEILISEARCH_HOST'],
5+
meilisearch_api_key: ENV['MEILISEARCH_API_KEY'],
6+
}
7+
8+
describe MeiliSearch::Configuration do
9+
let(:configuration) {
10+
{
11+
meilisearch_host: "http://localhost:7700",
12+
meilisearch_api_key: "s3cr3tap1k3y",
13+
}
14+
}
15+
16+
before do
17+
allow(MeiliSearch).to receive(:configuration) { configuration }
18+
end
19+
20+
describe ".client" do
21+
let(:client_double) { double MeiliSearch::Client }
22+
23+
before do
24+
allow(MeiliSearch::Client).to receive(:new) { client_double }
25+
end
26+
27+
it "initializes a MeiliSearch::Client" do
28+
expect(MeiliSearch.client).to eq(client_double)
29+
30+
expect(MeiliSearch::Client)
31+
.to have_received(:new)
32+
.with("http://localhost:7700", "s3cr3tap1k3y", {})
33+
end
34+
35+
context "with timeout and max retries" do
36+
let(:configuration) {
37+
{
38+
meilisearch_host: "http://localhost:7700",
39+
meilisearch_api_key: "s3cr3tap1k3y",
40+
timeout: 2,
41+
max_retries: 1,
42+
}
43+
}
44+
45+
it "forwards them to the client" do
46+
expect(MeiliSearch.client).to eq(client_double)
47+
48+
expect(MeiliSearch::Client)
49+
.to have_received(:new)
50+
.with(
51+
"http://localhost:7700",
52+
"s3cr3tap1k3y",
53+
timeout: 2,
54+
max_retries: 1,
55+
)
56+
end
57+
end
58+
end
59+
end

0 commit comments

Comments
 (0)