class Elbas::Retryable
Public Class Methods
delay(seconds, &block)
click to toggle source
# File lib/elbas/retryable.rb, line 37 def self.delay(seconds, &block) new.tap { |r| r.delay seconds } end
new()
click to toggle source
# File lib/elbas/retryable.rb, line 5 def initialize @max = 0 @delay = 0 end
times(max, &block)
click to toggle source
# File lib/elbas/retryable.rb, line 33 def self.times(max, &block) new.tap { |r| r.times max } end
Public Instance Methods
delay(seconds, &block)
click to toggle source
# File lib/elbas/retryable.rb, line 15 def delay(seconds, &block) @delay = seconds run block if block_given? end
run(proc)
click to toggle source
# File lib/elbas/retryable.rb, line 20 def run(proc) attempts ||= 0 attempts += 1 proc.call rescue => e info "Rescued error in retryable action: #{e.message}" if attempts < @max info "Retrying in #{@delay} seconds..." sleep @delay retry end end
times(max, &block)
click to toggle source
# File lib/elbas/retryable.rb, line 10 def times(max, &block) @max = max run block if block_given? end