Skip to content

Commit 75d3efb

Browse files
bertm13iMacTia
authored andcommitted
Scope retryable module under faraday module
1 parent f021508 commit 75d3efb

File tree

1 file changed

+34
-32
lines changed

1 file changed

+34
-32
lines changed

lib/faraday/retry/retryable.rb

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,46 @@
11
# frozen_string_literal: true
22

33
# Adds the ability to retry a request based on settings and errors that have occurred.
4-
module Retryable
5-
def with_retries(env:, options:, retries:, body:, errmatch:)
6-
yield
7-
rescue errmatch => e
8-
exhausted_retries(options, env, e) if retries_zero?(retries, env, e)
4+
module Faraday
5+
module Retryable
6+
def with_retries(env:, options:, retries:, body:, errmatch:)
7+
yield
8+
rescue errmatch => e
9+
exhausted_retries(options, env, e) if retries_zero?(retries, env, e)
910

10-
if retries.positive? && retry_request?(env, e)
11-
retries -= 1
12-
rewind_files(body)
13-
if (sleep_amount = calculate_sleep_amount(retries + 1, env))
14-
options.retry_block.call(
15-
env: env,
16-
options: options,
17-
retry_count: options.max - (retries + 1),
18-
exception: e,
19-
will_retry_in: sleep_amount
20-
)
21-
sleep sleep_amount
22-
retry
11+
if retries.positive? && retry_request?(env, e)
12+
retries -= 1
13+
rewind_files(body)
14+
if (sleep_amount = calculate_sleep_amount(retries + 1, env))
15+
options.retry_block.call(
16+
env: env,
17+
options: options,
18+
retry_count: options.max - (retries + 1),
19+
exception: e,
20+
will_retry_in: sleep_amount
21+
)
22+
sleep sleep_amount
23+
retry
24+
end
2325
end
24-
end
2526

26-
raise unless e.is_a?(Faraday::RetriableResponse)
27+
raise unless e.is_a?(Faraday::RetriableResponse)
2728

28-
e.response
29-
end
29+
e.response
30+
end
3031

31-
private
32+
private
3233

33-
def retries_zero?(retries, env, exception)
34-
retries.zero? && retry_request?(env, exception)
35-
end
34+
def retries_zero?(retries, env, exception)
35+
retries.zero? && retry_request?(env, exception)
36+
end
3637

37-
def exhausted_retries(options, env, exception)
38-
options.exhausted_retries_block.call(
39-
env: env,
40-
exception: exception,
41-
options: options
42-
)
38+
def exhausted_retries(options, env, exception)
39+
options.exhausted_retries_block.call(
40+
env: env,
41+
exception: exception,
42+
options: options
43+
)
44+
end
4345
end
4446
end

0 commit comments

Comments
 (0)