<commit_before>module Attender
  class Agent
    Signal.trap(:INT) { exit 0 }

    def initialize
      @url = 'localhost'
      @port = '8500'
      @timeout = 60
      @index = nil
      @response_queue = Queue.new
      STDOUT.sync = true
    end

    def run
      getter = Thread.new do
        path = '/v1/health/state/passing'
        loop do
          @response_queue << get(path)
        end
      end

      putter = Thread.new do
        loop do
          unless @response_queue.empty?
            put(@response_queue.pop)
          end
          sleep rand * 0.1
        end
      end

      getter.join
      putter.join
    end

    def get(path, lp = true)
      http = Net::HTTP.new(@url, @port)
      http.read_timeout = @timeout
      path+= "?wait=#{(@timeout-1).to_s}s&index=#{@index}" unless @index.nil? if lp
      response = http.get(path)

      code = response.code
      unless code == '200'
        abort("Invalid status code #{code}")
      end

      @index = response['x-consul-index']
      if @index.nil?
        abort('Missing x-consul-index')
      end

      response.body
    end

    def put(response)
      puts response
    end
  end
end<commit_msg>Show a additional diff and a additional diff<commit_after>require 'json'

module Attender
  class Agent
    Signal.trap(:INT) { exit 0 }

    def initialize
      @url = 'localhost'
      @port = '8500'
      @timeout = 60
      @index = nil
      @response_queue = Queue.new
      STDOUT.sync = true
      Thread.abort_on_exception = true
    end

    def run
      getter = Thread.new do
        path = '/v1/health/state/passing'
        loop do
          @response_queue << get(path)
        end
      end

      putter = Thread.new do
        response = nil
        loop do
          unless @response_queue.empty?
            prev_response = response
            response = @response_queue.pop
            put(response, prev_response)
          end
          sleep rand * 0.1
        end
      end

      getter.join
      putter.join
    end

    def get(path, lp = true)
      http = Net::HTTP.new(@url, @port)
      http.read_timeout = @timeout
      path+= "?wait=#{(@timeout-1).to_s}s&index=#{@index}" unless @index.nil? if lp
      response = http.get(path)

      code = response.code
      unless code == '200'
        raise "Invalid status code #{code}"
      end

      @index = response['x-consul-index']
      if @index.nil?
        raise 'Missing x-consul-index'
      end

      JSON.parse(response.body)
    end

    def put(response, prev_response)
      return if prev_response.nil?
      add_diff = response.select do |v|
        !prev_response.include?(v)
      end

      ded_diff = prev_response.select do |v|
        !response.include?(v)
      end

      puts add_diff.to_json
      puts ded_diff.to_json
    end
  end
end
{'fraction_non_alphanumeric': 0.10151568558336271, 'fraction_numerical': 0.00986958054282693, 'mean_word_length': 1.75266731328807, 'pattern_counts': {'":': 0, '<': 7, '<?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': '3671100', 'n_tokens_mistral': 914, 'n_tokens_neox': 882, 'n_words': 227}