Class: Respawn::Try
- Inherits:
-
Object
- Object
- Respawn::Try
- Defined in:
- lib/respawn/try.rb
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(*exceptions, **options) ⇒ Try
constructor
A new instance of Try.
Constructor Details
#initialize(*exceptions, **options) ⇒ Try
Returns a new instance of Try.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/respawn/try.rb', line 9 def initialize(*exceptions, **) .keys.each { OPTIONS.keys.try!(it) } self.setup = .fetch(:setup, Setup.new(**)) self.notifier = .fetch(:notifier, setup.notifier) self.predicate = .fetch(:predicate, setup.predicate) exceptions = setup.ex if exceptions.empty? self.exceptions = parse_exceptions(exceptions) + [PredicateError] self.tries = .fetch(:tries, setup.tries) self.onfail = ONFAIL.try! .fetch(:onfail, setup.onfail) self.wait = .fetch(:wait, setup.wait) self.env = .fetch(:env, Environment.default) self.handler = Handler.new(onfail) end |
Class Method Details
.call ⇒ Object
5 6 7 |
# File 'lib/respawn/try.rb', line 5 def self.call(*, **, &) new(*, **).call(&) end |
Instance Method Details
#call ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/respawn/try.rb', line 28 def call yield(handler) .tap(&method(:check_predicates)) rescue *exceptions => e self.tries = tries - 1 handler.retry_number += 1 if tries.positive? Kernel.sleep(wait) unless env.test? retry end perform_fail(e) end |