lib/tunemygc/syncer.rb in tunemygc-1.0.34 vs lib/tunemygc/syncer.rb in tunemygc-1.0.35
- old
+ new
@@ -4,17 +4,14 @@
module TuneMyGc
class Syncer
ENVIRONMENT = [ENV['RUBY_GC_TOKEN'], RUBY_VERSION, TuneMyGc.rails_version, ENV.select {|k,v| k =~ /RUBY_GC_/ }, TuneMyGc::VERSION, GC::OPTS, GC::INTERNAL_CONSTANTS].freeze
- attr_reader :uri, :client
+ attr_reader :client
def initialize(host = TuneMyGc::HOST)
- @uri = URI("http://#{host}/ruby")
- @client = Net::HTTP.new(@uri.host, @uri.port)
- @client.use_ssl = (uri.port == 443)
- @client.read_timeout = NETWORK_TIMEOUT
+ @client = TuneMyGc.http_client
end
def sync(snapshotter)
if sync_required?(snapshotter)
response = nil
@@ -56,11 +53,11 @@
snapshot = snapshotter.deq
TuneMyGc.log(snapshot) if debug
payload << snapshot
end
data = ActiveSupport::JSON.encode(payload)
- response = client.post(uri.path, data, TuneMyGc::HEADERS)
+ response = client.post('/ruby', data, TuneMyGc::HEADERS)
snapshotter.unit_of_work = false
if Net::HTTPNotFound === response
TuneMyGc.log "Invalid application token. Please generate one with 'bundle exec tunemygc <a_valid_email_address>' and set the RUBY_GC_TOKEN environment variable"
return false
elsif Net::HTTPNotImplemented === response
@@ -92,13 +89,9 @@
snapshotter.clear
end
def process_config_callback(response)
report_url = response.body.gsub(/\.json$/, '')
- config = client.get(URI(response.body).path)
- ActiveSupport::JSON.decode(config.body).merge('report' => report_url)
- rescue Exception => e
TuneMyGc.log "Please visit #{report_url} to view your configuration and other Garbage Collector insights"
- return false
end
end
end
\ No newline at end of file