<commit_before>module Backstop
  class Publisher
    attr_reader :connections, :api_key

    def initialize(urls, opts={})
      @connections = []
      @connections = urls.map { |u| URI.parse(u) }.map { |u| TCPSocket.new(u.host, u.port) }
      p @connections
      @api_key = opts[:api_key]
    end

    def metric_name(name)
      api_key ? "#{api_key}.#{name}" : name  
    end

    def publish(name, value, time=Time.now.to_i)
      c = connections.sample
      begin
        c.puts("#{metric_name(name)} #{value} #{time}")  
      rescue
        c.reopen(c)
        self.publish(name, value, time)
      end
    end
  end
end
<commit_msg>reopen notice<commit_after>module Backstop
  class Publisher
    attr_reader :connections, :api_key

    def initialize(urls, opts={})
      @connections = []
      @connections = urls.map { |u| URI.parse(u) }.map { |u| TCPSocket.new(u.host, u.port) }
      p @connections
      @api_key = opts[:api_key]
    end

    def metric_name(name)
      api_key ? "#{api_key}.#{name}" : name  
    end

    def publish(name, value, time=Time.now.to_i)
      c = connections.sample
      begin
        c.puts("#{metric_name(name)} #{value} #{time}")  
      rescue
        puts "connection lost, reopening socket"
        c.reopen(c)
        self.publish(name, value, time)
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.13537771129394166, 'fraction_numerical': 0.0, 'mean_word_length': 2.404580152671756, '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': '1649951', 'n_tokens_mistral': 471, 'n_tokens_neox': 466, 'n_words': 104}