Sha256: 17ef8b0179e3d4e0e5ba118e8dcbf45130cc11454043ca2172628b3336453726

Contents?: true

Size: 735 Bytes

Versions: 4

Compression:

Stored size: 735 Bytes

Contents

module Greenjaguar
  module Strategies
    class ExponentialBackoffStrategy < WaitStrategy
      def initialize
        super
        @retry_interval = 0.5
        @randomization_factor = 0.5
        @retry_count = 0
      end

      def reset_vars
        @retry_interval = 0.5 * convert_to(time_unit)
        @randomization_factor = 0.5
      end

      def wait
        sleep @retry_interval
        @retry_count += 1
        increment = (2 ** @retry_count - 1) * ([1 - @randomization_factor,
                                            1 + @randomization_factor][random_index])
        @retry_interval += increment * convert_to(time_unit)
      end

      private
      def random_index
        rand(2)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
greenjaguar-0.0.6 lib/greenjaguar/strategies/exponential_backoff_strategy.rb
greenjaguar-0.0.5 lib/greenjaguar/strategies/exponential_backoff_strategy.rb
greenjaguar-0.0.4 lib/greenjaguar/strategies/exponential_backoff_strategy.rb
greenjaguar-0.0.3 lib/greenjaguar/strategies/exponential_backoff_strategy.rb