class ScoutApm::Agent::ExitHandler

Attributes

context[R]

Public Class Methods

new(context) click to toggle source
# File lib/scout_apm/agent/exit_handler.rb, line 6
def initialize(context)
  @context = context
end

Public Instance Methods

install() click to toggle source
# File lib/scout_apm/agent/exit_handler.rb, line 10
def install
  logger.debug "Shutdown handler not supported" and return unless exit_handler_supported?
  logger.debug "Installing Shutdown Handler"

  at_exit do
    logger.info "Shutting down Scout Agent"
    # MRI 1.9 bug drops exit codes.
    # http://bugs.ruby-lang.org/issues/5218
    if environment.ruby_19?
      status = $!.status if $!.is_a?(SystemExit)
      shutdown
      exit status if status
    else
      shutdown
    end
  end
end

Private Instance Methods

environment() click to toggle source
# File lib/scout_apm/agent/exit_handler.rb, line 60
def environment
  context.environment
end
exit_handler_supported?() click to toggle source
# File lib/scout_apm/agent/exit_handler.rb, line 41
def exit_handler_supported?
  if environment.sinatra?
    logger.debug "Exit handler not supported for Sinatra"
    false
  elsif environment.jruby?
    logger.debug "Exit handler not supported for JRuby"
    false
  elsif environment.rubinius?
    logger.debug "Exit handler not supported for Rubinius"
    false
  else
    true
  end
end
logger() click to toggle source
# File lib/scout_apm/agent/exit_handler.rb, line 56
def logger
  context.logger
end
shutdown() click to toggle source

Called via the at_exit handler, it: (1) Stops the background worker (2) Stores metrics locally (forcing current-minute metrics to be written) It does not attempt to actually report metrics.

# File lib/scout_apm/agent/exit_handler.rb, line 34
def shutdown
  logger.info "Shutting down ScoutApm"
  return if !context.started?
  context.shutting_down!
  ::ScoutApm::Agent.instance.stop_background_worker
end