Class: Retry::Engine

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

Overview

Support for repeatedly calling retriable operations

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(delay: nil, exceptions: nil, handlers: nil, tries: nil) ⇒ void

Initialises a new Engine instance

Parameters:

  • delay (Float) (defaults to: nil)

    the default delay before retrying

  • exceptions (Hash<Exception, Boolean>) (defaults to: nil)

    the default retriable exceptions

  • handlers (Hash<Exception|Symbol, Proc>) (defaults to: nil)

    the default exception handlers

  • tries (Integer, Proc) (defaults to: nil)

    the default maximum number of tries or a proc which accepts an Exception and returns true if a retry is allowed or false if not



45
46
47
48
49
50
# File 'lib/retry.rb', line 45

def initialize(delay: nil, exceptions: nil, handlers: nil, tries: nil)
  self.delay = delay.to_f
  self.exceptions = exceptions || {}
  self.handlers = handlers || {}
  self.tries = tries
end

Instance Attribute Details

#delayObject

Returns the value of attribute delay.



30
31
32
# File 'lib/retry.rb', line 30

def delay
  @delay
end

#exceptionsObject

Returns the value of attribute exceptions.



31
32
33
# File 'lib/retry.rb', line 31

def exceptions
  @exceptions
end

#handlersObject

Returns the value of attribute handlers.



32
33
34
# File 'lib/retry.rb', line 32

def handlers
  @handlers
end

#triesObject

Returns the value of attribute tries.



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

def tries
  @tries
end

Instance Method Details

#do(delay: nil, exceptions: nil, handlers: nil, tries: nil, &block) ⇒ Object

Executes the class method do using instance default values



53
54
55
56
57
58
59
# File 'lib/retry.rb', line 53

def do(delay: nil, exceptions: nil, handlers: nil, tries: nil, &block)
  Retry.do(delay: delay || self.delay,
           exceptions: exceptions || self.exceptions,
           handlers: handlers || self.handlers,
           tries: tries || self.tries,
           &block)
end