class Coverband::Adapters::PersistentService
Attributes
http[R]
stats[R]
Public Class Methods
new(coverband_url, opts = {})
click to toggle source
Calls superclass method
Coverband::Adapters::Service::new
# File lib/coverband-service-client.rb, line 211 def initialize(coverband_url, opts = {}) super initiate_http end
Public Instance Methods
recommended_timeout()
click to toggle source
# File lib/coverband-service-client.rb, line 216 def recommended_timeout puts Net::HTTP::Persistent.detect_idle_timeout URI("#{coverband_url}/api/collector") end
Private Instance Methods
initiate_http()
click to toggle source
# File lib/coverband-service-client.rb, line 222 def initiate_http @http = Net::HTTP::Persistent.new name: 'coverband_persistent' @http.headers['Content-Type'] = 'application/json' @http.headers['Coverband-Token'] = api_key @http.open_timeout = COVERBAND_TIMEOUT @http.read_timeout = COVERBAND_TIMEOUT # the two below seem inconsistent in terms of how they are set # leaving off for now # @http.ssl_timeout = COVERBAND_TIMEOUT # @http.write_timeout = COVERBAND_TIMEOUT # default is 5-10 seconds but we report ever few min, heroku kills them # before our reporting period... ;( # @http.idle_timeout = 1000 end
save_coverage(data)
click to toggle source
# File lib/coverband-service-client.rb, line 237 def save_coverage(data) persistent_attempts = 0 begin if api_key.nil? puts "Coverband: Error: no Coverband API key was found!" return end post_uri = URI("#{coverband_url}/api/collector") post = Net::HTTP::Post.new post_uri.path body = { remote_uuid: SecureRandom.uuid, data: data }.to_json post.body = body logger&.info "Coverband: saving (#{post_uri}) #{body}" if Coverband.configuration.verbose res = http.request post_uri, post rescue Net::HTTP::Persistent::Error => e persistent_attempts += 1 http.shutdown initiate_http retry if persistent_attempts < 2 end rescue StandardError => e logger&.info "Coverband: Error while saving coverage #{e}" if Coverband.configuration.verbose || COVERBAND_ENABLE_DEV_MODE end