Class: BookingSync::Engine::Retryable

Inherits:
Object
  • Object
show all
Defined in:
lib/bookingsync/engine/retryable.rb

Class Method Summary collapse

Class Method Details

.perform(times:, errors:, before_retry: ->(_error) {}) ⇒ Object


2
3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/bookingsync/engine/retryable.rb', line 2

def self.perform(times:, errors:, before_retry: ->(_error) {})
  executed = 0
  begin
    executed += 1
    yield
  rescue *errors => error
    if executed < times
      before_retry.call(error)
      retry
    else
      raise error
    end
  end
end