antbird 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +4 -4
- data/README.md +61 -0
- data/lib/antbird/client.rb +57 -15
- data/lib/antbird/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2d00e228d8e4628e1e0a0f0fb34e0df4382c552266b1510f44734ef022757569
|
|
4
|
+
data.tar.gz: 6d4d6abd75ee27a4756eac51b6039b44f438f378ca4fe23ccd95905ce61eee25
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0a0e44ac7de86a2671b3571ba407dd262f01ed976bb70648e397d112ccd28b5c169397a528231105fc9fd7b175f427185beadfd0508cf523b000104313a92059
|
|
7
|
+
data.tar.gz: e2aaf781014694479d8710dfefa417a1e29b993600ecf043aab7b44713e66630143e3a4ae1550bc9328184d5b6a4948b47d4daa2f6b19f36681ae8c44e57e6ae
|
data/Gemfile.lock
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
antbird (1.
|
|
4
|
+
antbird (1.1.0)
|
|
5
5
|
faraday (>= 2.0.1)
|
|
6
6
|
|
|
7
7
|
GEM
|
|
8
8
|
remote: https://rubygems.org/
|
|
9
9
|
specs:
|
|
10
|
-
addressable (2.
|
|
10
|
+
addressable (2.9.0)
|
|
11
11
|
public_suffix (>= 2.0.2, < 8.0)
|
|
12
12
|
connection_pool (3.0.2)
|
|
13
13
|
diff-lcs (1.6.2)
|
|
14
|
-
faraday (2.14.
|
|
14
|
+
faraday (2.14.2)
|
|
15
15
|
faraday-net_http (>= 2.0, < 3.5)
|
|
16
16
|
json
|
|
17
17
|
logger
|
|
@@ -22,7 +22,7 @@ GEM
|
|
|
22
22
|
net-http-persistent (>= 4.0.4, < 5)
|
|
23
23
|
faraday-retry (2.4.0)
|
|
24
24
|
faraday (~> 2.0)
|
|
25
|
-
json (2.19.
|
|
25
|
+
json (2.19.5)
|
|
26
26
|
logger (1.7.0)
|
|
27
27
|
net-http (0.9.1)
|
|
28
28
|
uri (>= 0.11.1)
|
data/README.md
CHANGED
|
@@ -99,6 +99,67 @@ client.bulk(body: [
|
|
|
99
99
|
])
|
|
100
100
|
```
|
|
101
101
|
|
|
102
|
+
### Timeouts
|
|
103
|
+
|
|
104
|
+
Default connection timeouts are configured when the client is created:
|
|
105
|
+
|
|
106
|
+
```ruby
|
|
107
|
+
client = Antbird::Client.new(
|
|
108
|
+
read_timeout: 5, # seconds (default)
|
|
109
|
+
open_timeout: 2, # seconds (default)
|
|
110
|
+
write_timeout: 30, # seconds (default: nil => falls back to read_timeout)
|
|
111
|
+
)
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
`write_timeout` is optional. When omitted it is left unset and the adapter
|
|
115
|
+
falls back to `read_timeout` for the write phase, preserving existing behavior.
|
|
116
|
+
|
|
117
|
+
Timeouts can be overridden per operation. There are two ways to do it:
|
|
118
|
+
|
|
119
|
+
1. `http_timeout` — a shorthand that sets the `read`, `open` and `write`
|
|
120
|
+
timeouts all at once for that single request:
|
|
121
|
+
|
|
122
|
+
```ruby
|
|
123
|
+
# This request alone uses a 60s timeout for read/open/write.
|
|
124
|
+
client.search(body: { query: { match_all: {} } }, http_timeout: 60)
|
|
125
|
+
|
|
126
|
+
# Long-running reindex; give it more time without affecting other calls.
|
|
127
|
+
client.reindex(body: { source: { index: 'a' }, dest: { index: 'b' } }, http_timeout: 600)
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
2. `read_timeout` / `open_timeout` / `write_timeout` — override individual
|
|
131
|
+
phases. These may be combined with each other:
|
|
132
|
+
|
|
133
|
+
```ruby
|
|
134
|
+
client.bulk(body: [{ index: { _id: '1' } }, { field1: 'a' }], open_timeout: 3, write_timeout: 30)
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
When none of these is given, the client falls back to the values configured at
|
|
138
|
+
initialization time.
|
|
139
|
+
|
|
140
|
+
`http_timeout` is mutually exclusive with `read_timeout` / `open_timeout` /
|
|
141
|
+
`write_timeout`. Passing `http_timeout` together with any of them raises an
|
|
142
|
+
`ArgumentError`:
|
|
143
|
+
|
|
144
|
+
```ruby
|
|
145
|
+
client.search(body: { query: { match_all: {} } }, http_timeout: 60, open_timeout: 3) # => ArgumentError
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
All of the above are client-side (HTTP) timeouts and do not collide with the
|
|
149
|
+
server-side `timeout` query parameter that some OpenSearch APIs accept — both
|
|
150
|
+
can be passed together:
|
|
151
|
+
|
|
152
|
+
```ruby
|
|
153
|
+
client.bulk(
|
|
154
|
+
body: [{ index: { _id: '1' } }, { field1: 'a' }],
|
|
155
|
+
timeout: '30s', # OpenSearch server-side timeout (query parameter)
|
|
156
|
+
http_timeout: 60, # HTTP read/open/write timeout (Faraday)
|
|
157
|
+
)
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
> `read_timeout` sets Faraday's global `:timeout` (preserving its original
|
|
161
|
+
> behavior), while `open_timeout` / `write_timeout` set those specific phases.
|
|
162
|
+
|
|
102
163
|
## Development
|
|
103
164
|
|
|
104
165
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/antbird/client.rb
CHANGED
|
@@ -9,14 +9,16 @@ module Antbird
|
|
|
9
9
|
version: nil,
|
|
10
10
|
read_timeout: 5,
|
|
11
11
|
open_timeout: 2,
|
|
12
|
+
write_timeout: nil,
|
|
12
13
|
adapter: ::Faraday.default_adapter,
|
|
13
14
|
&block)
|
|
14
15
|
|
|
15
|
-
@read_timeout
|
|
16
|
-
@open_timeout
|
|
17
|
-
@
|
|
18
|
-
@
|
|
19
|
-
@
|
|
16
|
+
@read_timeout = read_timeout
|
|
17
|
+
@open_timeout = open_timeout
|
|
18
|
+
@write_timeout = write_timeout
|
|
19
|
+
@adapter = adapter
|
|
20
|
+
@block = block
|
|
21
|
+
@url = url
|
|
20
22
|
|
|
21
23
|
@scope = scope.transform_keys(&:to_sym)
|
|
22
24
|
|
|
@@ -25,7 +27,7 @@ module Antbird
|
|
|
25
27
|
@api_specs = {}
|
|
26
28
|
end
|
|
27
29
|
attr_reader :scope, :url
|
|
28
|
-
attr_reader :read_timeout, :open_timeout, :adapter
|
|
30
|
+
attr_reader :read_timeout, :open_timeout, :write_timeout, :adapter
|
|
29
31
|
attr_reader :api_specs, :last_request
|
|
30
32
|
|
|
31
33
|
def scoped(new_scope = {})
|
|
@@ -35,6 +37,7 @@ module Antbird
|
|
|
35
37
|
version: version,
|
|
36
38
|
read_timeout: read_timeout,
|
|
37
39
|
open_timeout: open_timeout,
|
|
40
|
+
write_timeout: write_timeout,
|
|
38
41
|
adapter: adapter,
|
|
39
42
|
&@block
|
|
40
43
|
)
|
|
@@ -84,7 +87,7 @@ module Antbird
|
|
|
84
87
|
methods.first
|
|
85
88
|
end
|
|
86
89
|
|
|
87
|
-
|
|
90
|
+
timeout_options = extract_timeout_options(params)
|
|
88
91
|
params.reject! { |_, v| v.nil? }
|
|
89
92
|
|
|
90
93
|
@last_request = {
|
|
@@ -100,29 +103,29 @@ module Antbird
|
|
|
100
103
|
when :head
|
|
101
104
|
connection.head(api_path) do |req|
|
|
102
105
|
req.params = params unless params.empty?
|
|
103
|
-
req
|
|
106
|
+
apply_timeouts(req, timeout_options)
|
|
104
107
|
end
|
|
105
108
|
when :get
|
|
106
109
|
connection.get(api_path) do |req|
|
|
107
110
|
req.params = params unless params.empty?
|
|
108
111
|
req.body = body if body
|
|
109
|
-
req
|
|
112
|
+
apply_timeouts(req, timeout_options)
|
|
110
113
|
end
|
|
111
114
|
when :put
|
|
112
115
|
connection.put(api_path, body) do |req|
|
|
113
116
|
req.params = params unless params.empty?
|
|
114
|
-
req
|
|
117
|
+
apply_timeouts(req, timeout_options)
|
|
115
118
|
end
|
|
116
119
|
when :post
|
|
117
120
|
connection.post(api_path, body) do |req|
|
|
118
121
|
req.params = params unless params.empty?
|
|
119
|
-
req
|
|
122
|
+
apply_timeouts(req, timeout_options)
|
|
120
123
|
end
|
|
121
124
|
when :delete
|
|
122
125
|
connection.delete(api_path) do |req|
|
|
123
126
|
req.params = params unless params.empty?
|
|
124
127
|
req.body = body if body
|
|
125
|
-
req
|
|
128
|
+
apply_timeouts(req, timeout_options)
|
|
126
129
|
end
|
|
127
130
|
else
|
|
128
131
|
raise ArgumentError, "Unknown HTTP request method: #{method.inspect}"
|
|
@@ -185,8 +188,9 @@ module Antbird
|
|
|
185
188
|
conn.request :json
|
|
186
189
|
conn.response :json, content_type: /\bjson$/
|
|
187
190
|
|
|
188
|
-
conn.options[:timeout]
|
|
189
|
-
conn.options[:open_timeout]
|
|
191
|
+
conn.options[:timeout] = read_timeout
|
|
192
|
+
conn.options[:open_timeout] = open_timeout
|
|
193
|
+
conn.options[:write_timeout] = write_timeout if write_timeout
|
|
190
194
|
|
|
191
195
|
conn.adapter adapter
|
|
192
196
|
end
|
|
@@ -201,6 +205,44 @@ module Antbird
|
|
|
201
205
|
|
|
202
206
|
private
|
|
203
207
|
|
|
208
|
+
# Builds the per-operation Faraday timeout options from the request params.
|
|
209
|
+
# - http_timeout: overrides read/open/write timeouts all at once. It is
|
|
210
|
+
# mutually exclusive with read_timeout/open_timeout/write_timeout.
|
|
211
|
+
# - read_timeout: legacy per-operation override (sets Faraday's :timeout).
|
|
212
|
+
# - open_timeout / write_timeout: per-operation overrides for those phases.
|
|
213
|
+
# The granular options may be combined with each other.
|
|
214
|
+
# When none is given, the connection-level defaults are used.
|
|
215
|
+
#
|
|
216
|
+
# The read phase is set via Faraday's :timeout key (consistent with the
|
|
217
|
+
# legacy read_timeout path and the connection-level default); :open_timeout
|
|
218
|
+
# and :write_timeout are set explicitly so http_timeout overrides them even
|
|
219
|
+
# when the connection configures its own defaults.
|
|
220
|
+
def extract_timeout_options(params)
|
|
221
|
+
http_timeout = params.delete(:http_timeout)
|
|
222
|
+
read_timeout = params.delete(:read_timeout)
|
|
223
|
+
open_timeout = params.delete(:open_timeout)
|
|
224
|
+
write_timeout = params.delete(:write_timeout)
|
|
225
|
+
|
|
226
|
+
if http_timeout && (read_timeout || open_timeout || write_timeout)
|
|
227
|
+
raise ArgumentError,
|
|
228
|
+
":http_timeout cannot be combined with :read_timeout, :open_timeout or :write_timeout"
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
if http_timeout
|
|
232
|
+
return { timeout: http_timeout, open_timeout: http_timeout, write_timeout: http_timeout }
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
options = {}
|
|
236
|
+
options[:timeout] = read_timeout if read_timeout
|
|
237
|
+
options[:open_timeout] = open_timeout if open_timeout
|
|
238
|
+
options[:write_timeout] = write_timeout if write_timeout
|
|
239
|
+
options
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
def apply_timeouts(req, timeout_options)
|
|
243
|
+
timeout_options.each { |key, value| req.options[key] = value }
|
|
244
|
+
end
|
|
245
|
+
|
|
204
246
|
# NOTE: stable sort
|
|
205
247
|
def sort_url_paths(url_paths)
|
|
206
248
|
i = 0
|
|
@@ -221,7 +263,7 @@ module Antbird
|
|
|
221
263
|
end
|
|
222
264
|
end
|
|
223
265
|
|
|
224
|
-
SPECIAL_PARAMS = %i[body method read_timeout].freeze
|
|
266
|
+
SPECIAL_PARAMS = %i[body method http_timeout read_timeout open_timeout write_timeout].freeze
|
|
225
267
|
|
|
226
268
|
def validate_params(api_spec, params, path_params)
|
|
227
269
|
if api_spec.dig('body', 'required') && !params.key?(:body)
|
data/lib/antbird/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: antbird
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- fukayatsu
|
|
@@ -143,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
143
143
|
- !ruby/object:Gem::Version
|
|
144
144
|
version: '0'
|
|
145
145
|
requirements: []
|
|
146
|
-
rubygems_version: 4.0.
|
|
146
|
+
rubygems_version: 4.0.10
|
|
147
147
|
specification_version: 4
|
|
148
148
|
summary: Nearly auto-generated OpenSearch client
|
|
149
149
|
test_files: []
|