Class: ScoutApm::ServerIntegrations::Unicorn

Inherits:
Object
  • Object
show all
Defined in:
lib/scout_apm/server_integrations/unicorn.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger) ⇒ Unicorn

Returns a new instance of Unicorn.



6
7
8
# File 'lib/scout_apm/server_integrations/unicorn.rb', line 6

def initialize(logger)
  @logger = logger
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



4
5
6
# File 'lib/scout_apm/server_integrations/unicorn.rb', line 4

def logger
  @logger
end

Instance Method Details

#forking?Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
20
21
# 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].tap {|x|
    logger.info "Unicorn is forking? #{x}"
  }
rescue
  true
end

#found?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/scout_apm/server_integrations/unicorn.rb', line 59

def found?
  true
end

#installObject



48
49
50
51
52
53
54
55
56
57
# File 'lib/scout_apm/server_integrations/unicorn.rb', line 48

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

#nameObject



10
11
12
# File 'lib/scout_apm/server_integrations/unicorn.rb', line 10

def name
  :unicorn
end

#present?Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/scout_apm/server_integrations/unicorn.rb', line 23

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