<commit_before>module Buildbox
  class API
    require 'net/http'
    require 'openssl'
    require 'json'

    def initialize(options)
      @options = options
    end

    def crash(exception, information = {})
      payload = {
        :exception => exception.class.name,
        :message   => exception.message,
        :backtrace => exception.backtrace,
        :meta      => {}
      }

      payload[:meta][:worker_uuid] = worker_uuid if worker_uuid
      payload[:meta][:build_uuid]  = information[:build] if information[:build]
      payload[:meta][:client_version] = Buildbox::VERSION

      request(:post, "crashes", payload)
    end

    def register(payload)
      request(:post, "workers", payload)
    end

    def login
      request(:get, "user")
    end

    def builds(options = {})
      request(:get, "workers/#{worker_uuid}/builds")
    end

    def update_build_state(build_uuid, state)
      request(:put, "workers/#{worker_uuid}/builds/#{build_uuid}", :state => state)
    end

    def update_build_result(build_uuid, result_uuid, attributes)
      request(:put, "workers/#{worker_uuid}/builds/#{build_uuid}/results/#{result_uuid}", attributes)
    end

    private

    def http(uri)
      Net::HTTP.new(uri.host, uri.port).tap do |http|
        http.use_ssl     = uri.scheme == "https"
        http.verify_mode = OpenSSL::SSL::VERIFY_NONE<commit_msg>Trying to put updating build status and result into a thread.<commit_after>module Buildbox
  class API
    require 'net/http'
    require 'openssl'
    require 'json'

    def initialize(options)
      @options = options
    end

    def crash(exception, information = {})
      payload = {
        :exception => exception.class.name,
        :message   => exception.message,
        :backtrace => exception.backtrace,
        :meta      => {}
      }

      payload[:meta][:worker_uuid] = worker_uuid if worker_uuid
      payload[:meta][:build_uuid]  = information[:build] if information[:build]
      payload[:meta][:client_version] = Buildbox::VERSION

      request(:post, "crashes", payload)
    end

    def register(payload)
      request(:post, "workers", payload)
    end

    def login
      request(:get, "user")
    end

    def builds(options = {})
      request(:get, "workers/#{worker_uuid}/builds")
    end

    def update_build_state(build_uuid, state)
      Thread.new { request(:put, "workers/#{worker_uuid}/builds/#{build_uuid}", :state => state) }
    end

    def update_build_result(build_uuid, result_uuid, attributes)
      Thread.new { request(:put, "workers/#{worker_uuid}/builds/#{build_uuid}/results/#{result_uuid}", attributes) }
    end

    private

    def http(uri)
      Net::HTTP.new(uri.host, uri.port).tap do |http|
        http.use_ssl     = uri.scheme == "https"
        http.verify_mode = OpenSSL::SSL::VERIFY_NONE
{'fraction_non_alphanumeric': 0.13241525423728814, 'fraction_numerical': 0.0, 'mean_word_length': 2.9129834254143647, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '4469452', 'n_tokens_mistral': 862, 'n_tokens_neox': 841, 'n_words': 179}