Skip to content
This repository was archived by the owner on Aug 27, 2021. It is now read-only.

Commit 6da5e56

Browse files
[gardening] add default randomness, add back faraday defaults for
retries
1 parent 6f68705 commit 6da5e56

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

README.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,17 @@ As well as `timeout: num_seconds` which can set the entire open/read (essentiall
104104

105105
**Retry**
106106

107-
Automatically enabled, the retry middleware will retry the request in case of network errors. By default, the middleware will retry up to 3 times, waiting 1 second between the retries.
107+
Automatically enabled, the retry middleware will retry the request in case of network errors. By default, the middleware will retry up to [3 times, with interval and backoff set to 1](https://github.com/wework/we-call-gem/blob/6f6870522a7ae057c8a103148a0a429431d3e1c8/lib/we/call/connection.rb#L17). Please be aware that adjusting the interval, backoff, or randomness factor will
108+
affect the total amount of time spent waiting for requests and retrying. For
109+
example:
110+
111+
| Cumulative time spent in retries | First Retry | Second Retry | Third Retry |
112+
|---------| ---------------| :-------------:| :------------:|
113+
| timeout=2s, backoff=1, interval=1 | 2s + 1s ≈ 3s (+/- 0.5s) | 3s + 2s + 1s ≈ 5s (+/- 0.5s) | 5s + 2s + 1s ≈ 8s (+/- 0.5s)
114+
| timeout=5s, backoff=1, interval=1 | 5s + 1s ≈ 6s (+/- 0.5s) | 6s + 5s + 1s ≈ 12s (+/- 0.5s) | 12s + 5s + 1s ≈ 18s (+/- 0.5s)
115+
| timeout=2s, backoff=1.5, interval=1 | 2s + 1.5s ≈ 3.5s (+/- 0.5s) | 3.5s + 2s + 2.25s ≈ 7.75s (+/- 0.5s) | 7.75s + 2s + 3.375s ≈ 13.125s (+/- 0.5s)
116+
| timeout=5s, backoff=1.5, interval=1 | 5s + 1.5s ≈ 6.5s (+/- 0.5s) | 6.5s + 5s + 2.25s ≈ 13.75s (+/- 0.5s) | 13.75s + 5s + 3.375s ≈ 22.125s (+/- 0.5s)
117+
108118

109119
Disable the middleware:
110120

lib/we/call/connection.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ module Connection
1717
DEFAULT_RETRY_OPTIONS = {
1818
max: 3,
1919
interval: 1,
20-
exceptions: [Faraday::ConnectionFailed, Faraday::TimeoutError]
20+
interval_randomness: 0.5,
21+
# After upgrading Faraday to 1.0+, use Faraday::Request::Retry::DEFAULT_EXCEPTIONS
22+
exceptions: [Faraday::ConnectionFailed, Errno::ETIMEDOUT, 'Timeout::Error', Error::TimeoutError]
2123
}
2224

2325
class MissingApp < ArgumentError; end

0 commit comments

Comments
 (0)