Skip to content

Commit 6d8605a

Browse files
fix(ruby): Implement host reset (generated)
algolia/api-clients-automation#5922 Co-authored-by: algolia-bot <accounts+algolia-api-client-bot@algolia.com> Co-authored-by: Mario-Alexandru Dan <marioalexandrudan@gmail.com>
1 parent dee536b commit 6d8605a

3 files changed

Lines changed: 8 additions & 6 deletions

File tree

lib/algolia/defaults.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
module Algolia
22
module Defaults
33
TTL = 300
4+
READ_TIMEOUT = 5000
5+
WRITE_TIMEOUT = 30000
6+
CONNECT_TIMEOUT = 2000
47
end
58
end

lib/algolia/transport/retry_strategy.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ def get_tryable_hosts(call_type)
4343
def decide(tryable_host, http_response_code: nil, is_timed_out: false, network_failure: false)
4444
@lock.synchronize do
4545
if !is_timed_out && success?(http_response_code)
46-
tryable_host.up = true
47-
tryable_host.last_use = Time.now.utc
46+
reset(tryable_host)
4847
SUCCESS
4948
elsif !is_timed_out && retryable?(http_response_code, network_failure)
5049
tryable_host.up = false

lib/algolia/transport/transport.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ def request(call_type, method, path, body, opts = {})
4242
retry_errors = []
4343

4444
@retry_strategy.get_tryable_hosts(call_type).each do |host|
45-
opts[:timeout] ||= get_timeout(call_type) * (host.retry_count + 1)
46-
opts[:connect_timeout] ||= @config.connect_timeout * (host.retry_count + 1)
45+
opts[:timeout] ||= get_timeout(call_type)
46+
opts[:connect_timeout] ||= (@config.connect_timeout || Defaults::CONNECT_TIMEOUT) * (host.retry_count + 1)
4747

4848
request_options = RequestOptions.new(@config)
4949
request_options.create(opts)
@@ -153,9 +153,9 @@ def generate_header_params(body, request_options)
153153
def get_timeout(call_type)
154154
case call_type
155155
when READ
156-
@config.read_timeout
156+
@config.read_timeout || Defaults::READ_TIMEOUT
157157
else
158-
@config.write_timeout
158+
@config.write_timeout || Defaults::WRITE_TIMEOUT
159159
end
160160
end
161161
end

0 commit comments

Comments
 (0)