lib/heimdall_apm/agent.rb in heimdall_apm-0.1.1 vs lib/heimdall_apm/agent.rb in heimdall_apm-0.1.2

- old
+ new

@@ -54,15 +54,19 @@ require 'heimdall_apm/instruments/middleware' # TODO: make the position configurable options[:app].config.middleware.insert_after Rack::Cors, HeimdallApm::Instruments::Middleware end + # TODO: handle platform/webserver that don't handle this correctly + at_exit { stop } + context.started! @background_thread = Thread.new { background_run } end def stop + HeimdallApm.logger.info 'Stopping agent...' @stopped = true context.stopped! if @background_thread.alive? @background_thread.wakeup @background_thread.join @@ -77,10 +81,14 @@ next_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) + DEFAULT_PUSH_INTERVAL loop do now = Process.clock_gettime(Process::CLOCK_MONOTONIC) - break if @stopped + if @stopped + # Commit data before stopping + reporting.call + break + end if now < next_time remaining = next_time - now HeimdallApm.logger.debug "Sleeping for #{remaining}" sleep(remaining)