class ScoutApm::ServerIntegrations::Unicorn

Attributes

logger[R]

Public Class Methods

new(logger) click to toggle source
# File lib/scout_apm/server_integrations/unicorn.rb, line 6
def initialize(logger)
  @logger = logger
end

Public Instance Methods

forking?() click to toggle source
# File lib/scout_apm/server_integrations/unicorn.rb, line 14
def forking?
  return true unless (defined?(::Unicorn) && defined?(::Unicorn::Configurator))
  ObjectSpace.each_object(::Unicorn::Configurator).first[:preload_app]
rescue
  true
end
found?() click to toggle source
# File lib/scout_apm/server_integrations/unicorn.rb, line 57
def found?
  true
end
install() click to toggle source
# File lib/scout_apm/server_integrations/unicorn.rb, line 46
def install
  logger.info "Installing Unicorn worker loop."
  ::Unicorn::HttpServer.class_eval do
    old = instance_method(:worker_loop)
    define_method(:worker_loop) do |worker|
      ScoutApm::Agent.instance.start_background_worker
      old.bind(self).call(worker)
    end
  end
end
name() click to toggle source
# File lib/scout_apm/server_integrations/unicorn.rb, line 10
def name
  :unicorn
end
present?() click to toggle source
# File lib/scout_apm/server_integrations/unicorn.rb, line 21
def present?
  if defined?(::Unicorn)
    logger.debug "[UNICORN] - ::Unicorn is defined"
  else
    logger.debug "[UNICORN] - ::Unicorn was not found"
    return false
  end

  if defined?(::Unicorn::HttpServer)
    logger.debug "[UNICORN] - ::Unicorn::HttpServer is defined"
  else
    logger.debug "[UNICORN] - ::Unicorn::HttpServer was not found"
    return false
  end

  # Ensure Unicorn is actually initialized. It could just be required and not running.
  ObjectSpace.each_object(::Unicorn::HttpServer) do |x|
    logger.debug "[UNICORN] - Running ::Unicorn::HttpServer found."
    return true
  end

  logger.debug "[UNICORN] - Running ::Unicorn::HttpServer was not found."
  false
end