<commit_before>require 'travis/support/logging'
require 'travis/support/retryable'

module Travis
  module Hub
    class Solo
      include Travis::Logging
      include Travis::Retryable

      DEFAULT_SUBSCRIBER_COUNT = 2

      def setup
        Travis::Async.enabled = true
        Travis::Amqp.config = Travis.config.amqp

        Travis::Database.connect
        if Travis.config.logs_database
          Log.establish_connection 'logs_database'
          Log::Part.establish_connection 'logs_database'
        end

        Travis::Async::Sidekiq.setup(Travis.config.redis.url, Travis.config.sidekiq)

        Travis::Exceptions::Reporter.start
        Travis::Metrics.setup
        Travis::Notification.setup
        Travis::Addons.register

        declare_exchanges_and_queues
      end

      attr_accessor :name, :count
      def initialize(name, count = nil)
        @name  = name
        @count = count ? Integer(count[/\d+/]) : DEFAULT_SUBSCRIBER_COUNT
      end

      def run
        enqueue_jobs
        subscribe_to_queue
      end

      private

        def subscribe_to_queue
          1.upto(count) do |num|
            Queue.subscribe(queue, &method(:handle))
          end
        end

        def queue
          'builds'
        end

        def handle(event, payload)
          retryable(tries: 5) do
            Metriks.timer("hub.#{name}.handle").time do
              ActiveRecord::Base.connection.begin_db_transaction
              ActiveRecord::Base.connection.execute('SET TRANSACTION ISOLATION LEVEL SERIALIZABLE')
              ActiveRecord::Base.cache do
                handle_event(event, payload)
              end
              ActiveRecord::Base.connection.commit_db_transaction
            end
          end<commit_msg>increase the retries and add a sleep<commit_after>require 'travis/support/logging'
require 'travis/support/retryable'

module Travis
  module Hub
    class Solo
      include Travis::Logging
      include Travis::Retryable

      DEFAULT_SUBSCRIBER_COUNT = 2

      def setup
        Travis::Async.enabled = true
        Travis::Amqp.config = Travis.config.amqp

        Travis::Database.connect
        if Travis.config.logs_database
          Log.establish_connection 'logs_database'
          Log::Part.establish_connection 'logs_database'
        end

        Travis::Async::Sidekiq.setup(Travis.config.redis.url, Travis.config.sidekiq)

        Travis::Exceptions::Reporter.start
        Travis::Metrics.setup
        Travis::Notification.setup
        Travis::Addons.register

        declare_exchanges_and_queues
      end

      attr_accessor :name, :count
      def initialize(name, count = nil)
        @name  = name
        @count = count ? Integer(count[/\d+/]) : DEFAULT_SUBSCRIBER_COUNT
      end

      def run
        enqueue_jobs
        subscribe_to_queue
      end

      private

        def subscribe_to_queue
          1.upto(count) do |num|
            Queue.subscribe(queue, &method(:handle))
          end
        end

        def queue
          'builds'
        end

        def handle(event, payload)
          retryable(tries: 10, sleep: 1) do
            Metriks.timer("hub.#{name}.handle").time do
              ActiveRecord::Base.connection.begin_db_transaction
              ActiveRecord::Base.connection.execute('SET TRANSACTION ISOLATION LEVEL SERIALIZABLE')
              ActiveRecord::Base.cache do
                handle_event(event, payload)
              end
              ActiveRecord::Base.connection.commit_db_transaction
            end
          end
{'fraction_non_alphanumeric': 0.0799099606077659, 'fraction_numerical': 0.0022509848058525606, 'mean_word_length': 2.056749785038693, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '1513062', 'n_tokens_mistral': 1032, 'n_tokens_neox': 998, 'n_words': 193}