Class: ScoutApm::ServerIntegrations::Puma
- Inherits:
-
Object
- Object
- ScoutApm::ServerIntegrations::Puma
- Defined in:
- lib/scout_apm/server_integrations/puma.rb
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
- #forking? ⇒ Boolean
- #found? ⇒ Boolean
-
#initialize(logger) ⇒ Puma
constructor
A new instance of Puma.
-
#install ⇒ Object
Puma::UserFileDefaultOptions exposes ‘options` based on three underlying hashes: user_options, file_options, and default_options.
- #name ⇒ Object
- #present? ⇒ Boolean
Constructor Details
#initialize(logger) ⇒ Puma
Returns a new instance of Puma.
6 7 8 |
# File 'lib/scout_apm/server_integrations/puma.rb', line 6 def initialize(logger) @logger = logger end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
4 5 6 |
# File 'lib/scout_apm/server_integrations/puma.rb', line 4 def logger @logger end |
Instance Method Details
#forking? ⇒ Boolean
14 15 16 17 18 19 20 |
# File 'lib/scout_apm/server_integrations/puma.rb', line 14 def forking? return false unless defined?(::Puma) = ::Puma.cli_config.instance_variable_get(:@options) [:preload_app] rescue false end |
#found? ⇒ Boolean
66 67 68 |
# File 'lib/scout_apm/server_integrations/puma.rb', line 66 def found? true end |
#install ⇒ Object
Puma::UserFileDefaultOptions exposes ‘options` based on three underlying hashes: user_options, file_options, and default_options. While getting an `options` key consults all three underlying hashes, setting an `options` key only sets the user_options hash:
def [](key)
fetch(key)
end
def []=(key, value)
[key] = value
end
def fetch(key, default_value = nil)
return [key] if .key?(key)
return [key] if .key?(key)
return [key] if .key?(key)
default_value
end
Because of this, we can’t read options, modify, and then re-set options, since doing so could cause duplication if ‘before_worker_boot` exists on the other two underlying hashes (file_options, default_options).
To get around this, we explicitly read from ‘user_options` only, and still set using `options[]=`, which Puma allows for setting `user_options`.
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/scout_apm/server_integrations/puma.rb', line 54 def install old = ::Puma.cli_config..[:before_worker_boot] || [] new = Array(old) + [Proc.new do logger.info "Installing Puma worker loop." ScoutApm::Agent.instance.start_background_worker end] ::Puma.cli_config.[:before_worker_boot] = new rescue logger.warn "Unable to install Puma worker loop: #{$!.message}" end |
#name ⇒ Object
10 11 12 |
# File 'lib/scout_apm/server_integrations/puma.rb', line 10 def name :puma end |
#present? ⇒ Boolean
22 23 24 |
# File 'lib/scout_apm/server_integrations/puma.rb', line 22 def present? defined?(::Puma) && (File.basename($0) =~ /\Apuma/) end |