Class: Undertaker::Undertaker

Inherits:
Object
  • Object
show all
Defined in:
lib/undertaker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Undertaker

Returns a new instance of Undertaker.



14
15
16
17
18
19
# File 'lib/undertaker.rb', line 14

def initialize(options = {})
  @exceptions = []
  @attempts = 0
  @limit = options[:limit] || 10
  @logger = options[:logger] || ActiveSupport::Logger.new(STDOUT)
end

Instance Attribute Details

#attemptsObject

Returns the value of attribute attempts.



11
12
13
# File 'lib/undertaker.rb', line 11

def attempts
  @attempts
end

#limitObject (readonly)

Returns the value of attribute limit.



12
13
14
# File 'lib/undertaker.rb', line 12

def limit
  @limit
end

#retry_conditionObject

Returns the value of attribute retry_condition.



11
12
13
# File 'lib/undertaker.rb', line 11

def retry_condition
  @retry_condition
end

Instance Method Details

#executeObject



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/undertaker.rb', line 21

def execute
  setup_execution
  yield
rescue StandardError => exception
  add_exception exception
  if should_retry?
    setup_retry
    retry
  end
  raise exception
end

#retry_when(&block) ⇒ Object



33
34
35
# File 'lib/undertaker.rb', line 33

def retry_when(&block)
  self.retry_condition = block
end