Module: Sufia::Utils::ClassMethods
- Defined in:
- lib/sufia/models/utils.rb
Instance Method Summary collapse
-
#retry_unless(number_of_tries, condition, &_block) ⇒ Object
retry the block if the conditional call is true unless we hit the maximum tries.
Instance Method Details
#retry_unless(number_of_tries, condition, &_block) ⇒ Object
retry the block if the conditional call is true unless we hit the maximum tries
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/sufia/models/utils.rb', line 25 def retry_unless(number_of_tries, condition, &_block) raise ArgumentError, "First argument must be an enumerator" unless number_of_tries.is_a? Enumerator raise ArgumentError, "Second argument must be a lambda" unless condition.respond_to? :call raise ArgumentError, "Must pass a block of code to retry" unless block_given? number_of_tries.each do result = yield return result unless condition.call sleep(Sufia.config.retry_unless_sleep) if Sufia.config.retry_unless_sleep > 0 end raise "retry_unless could not complete successfully. Try upping the # of tries?" end |