Class: MercadoPublicoCl::Retryer
- Inherits:
-
Object
- Object
- MercadoPublicoCl::Retryer
- Defined in:
- lib/mercado_publico_cl/retryer.rb
Constant Summary collapse
- RETRYABLE =
{ RateLimitError => :rate_limit, TimeoutError => :timeout, ApiError => :server_error }.freeze
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(configuration) ⇒ Retryer
constructor
A new instance of Retryer.
Constructor Details
#initialize(configuration) ⇒ Retryer
Returns a new instance of Retryer.
13 14 15 |
# File 'lib/mercado_publico_cl/retryer.rb', line 13 def initialize(configuration) @configuration = configuration end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
11 12 13 |
# File 'lib/mercado_publico_cl/retryer.rb', line 11 def configuration @configuration end |
Instance Method Details
#call ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/mercado_publico_cl/retryer.rb', line 17 def call attempts = 0 max_attempts = configuration.max_retries.to_i + 1 begin attempts += 1 yield rescue *RETRYABLE.keys => e raise e unless retryable?(e) && attempts < max_attempts wait = wait_for(e, attempts) log_retry(e, attempts, max_attempts, wait) sleep(wait) retry end end |