Sha256: f90a5c9dd69d607f7f4bd99565708ff6393e19951225e5f38afa0be4021a1d06

Contents?: true

Size: 1.13 KB

Versions: 3

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

module Buildkite::TestCollector
  class Uploader
    MAX_UPLOAD_ATTEMPTS = 3

    def self.traces
      @traces ||= {}
    end

    REQUEST_EXCEPTIONS = [
      URI::InvalidURIError,
      Net::HTTPBadResponse,
      Net::HTTPHeaderSyntaxError,
      Net::ReadTimeout,
      Net::OpenTimeout,
      OpenSSL::SSL::SSLError,
      OpenSSL::SSL::SSLErrorWaitReadable,
      EOFError
    ]

    RETRYABLE_UPLOAD_ERRORS = [
      Net::ReadTimeout,
      Net::OpenTimeout,
      OpenSSL::SSL::SSLError,
      OpenSSL::SSL::SSLErrorWaitReadable,
      EOFError
    ]

    def self.tracer
      Thread.current[:_buildkite_tracer]
    end

    def self.upload(data)
      return false unless Buildkite::TestCollector.api_token

      http = Buildkite::TestCollector::HTTPClient.new(Buildkite::TestCollector.url)

      Thread.new do
        response = begin
          upload_attempts ||= 0
          http.post_json(data)
        rescue *Buildkite::TestCollector::Uploader::RETRYABLE_UPLOAD_ERRORS => e
          if (upload_attempts += 1) < MAX_UPLOAD_ATTEMPTS
            retry
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
buildkite-test_collector-2.2.0 lib/buildkite/test_collector/uploader.rb
buildkite-test_collector-2.1.0 lib/buildkite/test_collector/uploader.rb
buildkite-test_collector-2.1.0.pre lib/buildkite/test_collector/uploader.rb