<commit_before>require 'cassanity/retry_strategies/retry_strategy'

module Cassanity
  module RetryStrategies
    class ExponentialBackoff < RetryStrategy
      ForeverSentinel = :forever

      # Taken from https://github.com/twitter/kestrel-client's blocking client.
      SLEEP_TIMES = [[0] * 1, [0.01] * 2, [0.1] * 2, [0.5] * 2, [1.0] * 1].flatten

      # Private: the maxmimum number of times to retry or -1 to try forever.
      attr_reader :retries

      # Public: Initialize the retry strategy.
      #
      # args   - The Hash of options.
      #          :retries - the maximum number of times to retry (default: forever)
      def initialize(args = {})
        # The default behavior is to retry forever.
        @retries = args[:retries] || ForeverSentinel
      end

      def fail(attempts, error)
        if @retries != ForeverSentinel && attempts > @retries
          raise error
        end
        sleep_for_count(attempts)
      end

      # Private: sleep a randomized amount of time from the
      # SLEEP_TIMES mostly-exponential distribution.
      #
      # count - the index into the distribution to pull the base sleep time from
      def sleep_for_count(count)
        base = SLEEP_TIMES[count] || SLEEP_TIMES.last

        time = ((rand * base) + base) / 2
        sleep time if time > 0
      end
    end
  end
end<commit_msg>Change sleep times to be same case as other constants.<commit_after>require 'cassanity/retry_strategies/retry_strategy'

module Cassanity
  module RetryStrategies
    class ExponentialBackoff < RetryStrategy
      ForeverSentinel = :forever

      # Taken from https://github.com/twitter/kestrel-client's blocking client.
      SleepTimes = [[0] * 1, [0.01] * 2, [0.1] * 2, [0.5] * 2, [1.0] * 1].flatten

      # Private: the maxmimum number of times to retry or -1 to try forever.
      attr_reader :retries

      # Public: Initialize the retry strategy.
      #
      # args   - The Hash of options.
      #          :retries - the maximum number of times to retry (default: forever)
      def initialize(args = {})
        # The default behavior is to retry forever.
        @retries = args[:retries] || ForeverSentinel
      end

      def fail(attempts, error)
        if @retries != ForeverSentinel && attempts > @retries
          raise error
        end
        sleep_for_count(attempts)
      end

      # Private: sleep a randomized amount of time from the SleepTimes
      # mostly-exponential distribution.
      #
      # count - the index into the distribution to pull the base sleep time from
      def sleep_for_count(count)
        base = SleepTimes[count] || SleepTimes.last

        time = ((rand * base) + base) / 2
        sleep time if time > 0
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.08463494369778424, 'fraction_numerical': 0.013076643661460226, 'mean_word_length': 2.306122448979592, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3829424', 'n_tokens_mistral': 848, 'n_tokens_neox': 802, 'n_words': 272}