Class: WhatsAppNotifier::Bulk::RetryPolicy

Inherits:
Object
  • Object
show all
Defined in:
lib/whatsapp_notifier/bulk/retry_policy.rb

Instance Method Summary collapse

Constructor Details

#initialize(max_attempts:, retryable_error_codes:) ⇒ RetryPolicy

Returns a new instance of RetryPolicy.



4
5
6
7
# File 'lib/whatsapp_notifier/bulk/retry_policy.rb', line 4

def initialize(max_attempts:, retryable_error_codes:)
  @max_attempts = max_attempts
  @retryable_error_codes = retryable_error_codes
end

Instance Method Details

#with_retriesObject



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/whatsapp_notifier/bulk/retry_policy.rb', line 9

def with_retries
  attempts = 0
  result = nil

  loop do
    attempts += 1
    result = yield(attempts)
    break unless retry?(result, attempts)
  end

  result
end