Sha256: 217e0eff500811543fc6d61c8b3e36e8e9bd92e8257850f53c38df44c0132c5d
Contents?: true
Size: 1.63 KB
Versions: 3
Compression:
Stored size: 1.63 KB
Contents
# This module includes utility methods module Sufia module Utils extend ActiveSupport::Concern # retry the block if the conditional call is true unless we hit the maximum tries # # @param number_of_tries [enumerator] maximum number of times to retry the block (eg. 7.times) # @param condition [#call] conditional to call and see if we SHOULD retry # @yeild block [] code you want to run and retry # # @return result of the block call def retry_unless(number_of_tries, condition, &block) self.class.retry_unless(number_of_tries, condition, &block) end module ClassMethods # retry the block if the conditional call is true unless we hit the maximum tries # # @param number_of_tries [enumerator] maximum number of times to retry the block # @param condition [#call] conditional to call and see if we SHOULD retry # @yeild block [] code you want to run and retry # # @return result of the block call 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 = block.call 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 end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
sufia-models-6.5.0 | lib/sufia/models/utils.rb |
sufia-models-6.4.0 | lib/sufia/models/utils.rb |
sufia-models-6.3.0 | lib/sufia/models/utils.rb |