Class: EventPeople::Broker::Rabbit::RetryManager
- Inherits:
-
Object
- Object
- EventPeople::Broker::Rabbit::RetryManager
- Defined in:
- lib/event_people/broker/rabbit/retry_manager.rb
Constant Summary collapse
- INITIAL_DELAY =
(ENV['RABBIT_EVENT_PEOPLE_RETRY_TTL_MS'] || 1000).to_i
- MAX_DELAY =
600_000
Instance Method Summary collapse
- #get_next_delay(retry_count) ⇒ Object
-
#initialize(max_attempts, delay_strategy = 'exponential') ⇒ RetryManager
constructor
A new instance of RetryManager.
- #should_retry?(retry_count) ⇒ Boolean
Constructor Details
#initialize(max_attempts, delay_strategy = 'exponential') ⇒ RetryManager
Returns a new instance of RetryManager.
7 8 9 10 |
# File 'lib/event_people/broker/rabbit/retry_manager.rb', line 7 def initialize(max_attempts, delay_strategy = 'exponential') @max_attempts = max_attempts @delay_strategy = delay_strategy end |
Instance Method Details
#get_next_delay(retry_count) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/event_people/broker/rabbit/retry_manager.rb', line 16 def get_next_delay(retry_count) if @delay_strategy == 'fixed' INITIAL_DELAY else [INITIAL_DELAY * (5**retry_count), MAX_DELAY].min end end |
#should_retry?(retry_count) ⇒ Boolean
12 13 14 |
# File 'lib/event_people/broker/rabbit/retry_manager.rb', line 12 def should_retry?(retry_count) retry_count < @max_attempts end |