Module: Wajub::RetryPolicy
- Defined in:
- lib/wajub/http/retry_policy.rb
Constant Summary collapse
- MAX_RETRIES =
2- RETRYABLE =
[429, 500, 502, 503, 504].freeze
Class Method Summary collapse
- .delay_seconds(attempt, response: nil) ⇒ Object
- .max_retries ⇒ Object
- .should_retry_status?(status) ⇒ Boolean
Class Method Details
.delay_seconds(attempt, response: nil) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/wajub/http/retry_policy.rb', line 18 def delay_seconds(attempt, response: nil) header = response&.[]('retry-after')&.strip if header && !header.empty? seconds = Integer(header, exception: false) return seconds if seconds time = Time.httpdate(header) rescue nil return [(time - Time.now).to_i, 0].max if time end 0.5 * (2**(attempt - 1)) end |
.max_retries ⇒ Object
14 15 16 |
# File 'lib/wajub/http/retry_policy.rb', line 14 def max_retries MAX_RETRIES end |
.should_retry_status?(status) ⇒ Boolean
10 11 12 |
# File 'lib/wajub/http/retry_policy.rb', line 10 def should_retry_status?(status) RETRYABLE.include?(status) end |