<commit_before>require 'faraday'

module Staccato
  module Rack
    # Proxy Class to do page views
    class FaradayHttpAdaper
      def initialize(logger = nil)
        @logger = logger
        @conn = Faraday.new(url: 'https://ssl.google-analytics.com') do |faraday|
          faraday.request :url_encoded             # form-encode POST params
          faraday.response :logger, @logger if @logger
          faraday.adapter Faraday.default_adapter  # make requests with Net::HTTP
        end
      end

      def post(data)
        Thread.new(data) do |body_data|
          @conn.post do |req|
            req.url '/collect'
            req.options.timeout = 1           # open/read timeout in seconds
            req.body = body_data
          end
        end
      end
    end
  end
end<commit_msg>log faraday connect errors and increase timeout to 2 seconds<commit_after>require 'faraday'

module Staccato
  module Rack
    # Proxy Class to do page views
    class FaradayHttpAdaper
      def initialize(logger = nil)
        @logger = logger
        @conn = Faraday.new(url: 'https://ssl.google-analytics.com') do |faraday|
          faraday.request :url_encoded             # form-encode POST params
          faraday.response :logger, @logger if @logger
          faraday.adapter Faraday.default_adapter  # make requests with Net::HTTP
        end
      end

      def post(data, url = '/collect')
        Thread.new(data, url) do
          begin
            execute(data, url)
          rescue => e
            @logger.error "Could not collect #{data.inspect} => #{e.message}"
          end
        end
      end

      private

      def execute(post_data, post_url)
        @conn.post do |req|
          req.url post_url
          req.options.timeout = 2           # open/read timeout in seconds
          req.body = post_data
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.07933972310969116, 'fraction_numerical': 0.001597444089456869, 'mean_word_length': 1.8170914542728636, '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': '1874267', 'n_tokens_mistral': 549, 'n_tokens_neox': 523, 'n_words': 159}