Class: Lazylead::ORM::Retry

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/lazylead/model.rb

Overview

A task which support retry in case of failure.

See Also:

Instance Method Summary collapse

Constructor Details

#initialize(orig, log = Log.new) ⇒ Retry

Returns a new instance of Retry.



211
212
213
214
# File 'lib/lazylead/model.rb', line 211

def initialize(orig, log = Log.new)
  @orig = orig
  @log = log
end

Instance Method Details

#execObject



216
217
218
219
220
221
222
223
224
225
# File 'lib/lazylead/model.rb', line 216

def exec
  retries ||= 0
  @orig.exec
  @orig
rescue StandardError => e
  sleep(props.fetch("attempt_wait", 0).to_f) if props.key? "attempt_wait"
  retry if (retries += 1) < props.fetch("attempt", 0).to_i
  raise e if props.key? "rethrow"
  @orig
end