Sha256: 48689f7a6bd924da71f87fcdf39ce78e09f0eb5207d8922649f8e6f5ca5ac677
Contents?: true
Size: 529 Bytes
Versions: 2
Compression:
Stored size: 529 Bytes
Contents
# frozen_string_literal: true # Exponential backoff retry wrapper class ExpRetry def initialize(retries: 3, exception: StandardError) @retries = retries @exception = exception end def call yield if block_given? rescue *@exception => e check(e) retry end private def check(e) retried > @retries ? raise(e) : delay(e) end def retried @retried ||= 0 @retried += 1 end def delay(e) puts "*** #{e}. Retrying in #{2**@retried} seconds..." sleep 2**@retried end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
exp_retry-0.0.7 | lib/exp_retry.rb |
exp_retry-0.0.6 | lib/exp_retry.rb |