<commit_before># encoding: utf-8

module Polipus
  module QueueOverflow
    module Enhancements

      def enhancements_logger(logger = nil)
        Logger.new(STDOUT).tap { |l| l.level = Logger::INFO } unless logger
      end

      module_function :enhancements_logger
      public :enhancements_logger

      RESCUED_CASSANDRA_EXCEPTIONS = [
        ::Cassandra::Errors::ExecutionError,
        ::Cassandra::Errors::IOError,
        ::Cassandra::Errors::InternalError,
        ::Cassandra::Errors::NoHostsAvailable,
        ::Cassandra::Errors::ServerError,
        ::Cassandra::Errors::TimeoutError
      ]

      # Trying to rescue from a Cassandra::Error
      #
      # The relevant documentation is here (version 2.1.3):
      # https://datastax.github.io/ruby-driver/api/error/
      #
      # Saving from:
      #
      # - ::Cassandra::Errors::ExecutionError
      # - ::Cassandra::Errors::IOError
      # - ::Cassandra::Errors::InternalError
      # - ::Cassandra::Errors::NoHostsAvailable
      # - ::Cassandra::Errors::ServerError
      # - ::Cassandra::Errors::TimeoutError
      #
      # Ignoring:
      # - Errors::ClientError
      # - Errors::DecodingError
      # - Errors::EncodingError
      # - Errors::ValidationError
      #
      # A possible and maybe-good refactoring could be refine for the
      # network related issues.
      def attempts_wrapper(attempts = 3, &block)
        (1..attempts).each do |i|
          begin
            return block.call() if block_given?
          rescue *RESCUED_CASSANDRA_EXCEPTIONS => e
            sleep_for = i * Random.rand(1.5..2.5)
            enhancements_logger.error { "(#{i}/#{attempts} attempts) Bad fail! Retry in #{sleep_for} seconds to recover  #{e.class.name}: #{e.message}" }
            sleep(sleep_for)
          end
        end
        nil
      end

      module_function :attempts_wrapper
      public :attempts_wrapper
    end
  end
end<commit_msg>FIXME! ... add a raise otherwise is a nop!<commit_after># encoding: utf-8

module Polipus
  module QueueOverflow
    module Enhancements

      def enhancements_logger(logger = nil)
        Logger.new(STDOUT).tap { |l| l.level = Logger::INFO } unless logger
      end

      module_function :enhancements_logger
      public :enhancements_logger

      RESCUED_CASSANDRA_EXCEPTIONS = [
        ::Cassandra::Errors::ExecutionError,
        ::Cassandra::Errors::IOError,
        ::Cassandra::Errors::InternalError,
        ::Cassandra::Errors::NoHostsAvailable,
        ::Cassandra::Errors::ServerError,
        ::Cassandra::Errors::TimeoutError
      ]

      # Trying to rescue from a Cassandra::Error
      #
      # The relevant documentation is here (version 2.1.3):
      # https://datastax.github.io/ruby-driver/api/error/
      #
      # Saving from:
      #
      # - ::Cassandra::Errors::ExecutionError
      # - ::Cassandra::Errors::IOError
      # - ::Cassandra::Errors::InternalError
      # - ::Cassandra::Errors::NoHostsAvailable
      # - ::Cassandra::Errors::ServerError
      # - ::Cassandra::Errors::TimeoutError
      #
      # Ignoring:
      # - Errors::ClientError
      # - Errors::DecodingError
      # - Errors::EncodingError
      # - Errors::ValidationError
      #
      # A possible and maybe-good refactoring could be refine for the
      # network related issues.
      def attempts_wrapper(attempts = 3, &block)
        (1..attempts).each do |i|
          begin
            return block.call() if block_given?
          rescue *RESCUED_CASSANDRA_EXCEPTIONS => e
            sleep_for = i * Random.rand(1.5..2.5)
            enhancements_logger.error { "(#{i}/#{attempts} attempts) Bad fail! Retry in #{sleep_for} seconds to recover  #{e.class.name}: #{e.message}" }
            sleep(sleep_for)
          end
        end
        ## FIXME!!
        raise 
        nil
      end

      module_function :attempts_wrapper
      public :attempts_wrapper
    end
  end
end
{'fraction_non_alphanumeric': 0.11625540574917324, 'fraction_numerical': 0.005087763927753753, 'mean_word_length': 2.37221269296741, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3006724', 'n_tokens_mistral': 1220, 'n_tokens_neox': 1155, 'n_words': 234}