Module: NewRelic::Agent::AgentHelpers::SpecialStartup
- Included in:
- NewRelic::Agent::Agent
- Defined in:
- lib/new_relic/agent/agent_helpers/special_startup.rb
Instance Method Summary collapse
- #defer_for_delayed_job? ⇒ Boolean
-
#defer_for_resque? ⇒ Boolean
Return true if we’re using resque and it hasn’t had a chance to (potentially) daemonize itself.
- #in_resque_child_process? ⇒ Boolean
- #install_exit_handler ⇒ Object
- #should_install_exit_handler? ⇒ Boolean
-
#sinatra_classic_app? ⇒ Boolean
This matters when the following three criteria are met:.
-
#using_forking_dispatcher? ⇒ Boolean
If we’re using a dispatcher that forks before serving requests, we need to wait until the children are forked before connecting, otherwise the parent process sends useless data.
Instance Method Details
#defer_for_delayed_job? ⇒ Boolean
35 36 37 38 |
# File 'lib/new_relic/agent/agent_helpers/special_startup.rb', line 35 def defer_for_delayed_job? NewRelic::Agent.config[:dispatcher] == :delayed_job && !NewRelic::DelayedJobInjection.worker_name end |
#defer_for_resque? ⇒ Boolean
Return true if we’re using resque and it hasn’t had a chance to (potentially) daemonize itself. This avoids hanging when there’s a Thread started before Resque calls Process.daemon (Jira RUBY-857)
25 26 27 28 29 |
# File 'lib/new_relic/agent/agent_helpers/special_startup.rb', line 25 def defer_for_resque? NewRelic::Agent.config[:dispatcher] == :resque && NewRelic::Agent::Instrumentation::Resque::Helper.resque_fork_per_job? && !PipeChannelManager.listener.started? end |
#in_resque_child_process? ⇒ Boolean
31 32 33 |
# File 'lib/new_relic/agent/agent_helpers/special_startup.rb', line 31 def in_resque_child_process? defined?(@service) && @service.is_a?(PipeService) end |
#install_exit_handler ⇒ Object
65 66 67 68 69 70 |
# File 'lib/new_relic/agent/agent_helpers/special_startup.rb', line 65 def install_exit_handler return unless should_install_exit_handler? NewRelic::Agent.logger.debug('Installing at_exit handler') at_exit { shutdown } end |
#should_install_exit_handler? ⇒ Boolean
59 60 61 62 63 |
# File 'lib/new_relic/agent/agent_helpers/special_startup.rb', line 59 def should_install_exit_handler? return false unless Agent.config[:send_data_on_exit] !sinatra_classic_app? || Agent.config[:force_install_exit_handler] end |
#sinatra_classic_app? ⇒ Boolean
This matters when the following three criteria are met:
-
A Sinatra ‘classic’ application is being run
-
The app is being run by executing the main file directly, rather than via a config.ru file.
-
newrelic_rpm is required after sinatra
In this case, the entire application runs from an at_exit handler in Sinatra, and if we were to install ours, it would be executed before the one in Sinatra, meaning that we’d shutdown the agent too early and never collect any data.
51 52 53 54 55 56 57 |
# File 'lib/new_relic/agent/agent_helpers/special_startup.rb', line 51 def sinatra_classic_app? ( defined?(Sinatra::Application) && Sinatra::Application.respond_to?(:run) && Sinatra::Application.run? ) end |
#using_forking_dispatcher? ⇒ Boolean
If we’re using a dispatcher that forks before serving requests, we need to wait until the children are forked before connecting, otherwise the parent process sends useless data
12 13 14 15 16 17 18 19 20 |
# File 'lib/new_relic/agent/agent_helpers/special_startup.rb', line 12 def using_forking_dispatcher? if [:puma, :passenger, :unicorn, :falcon].include?(Agent.config[:dispatcher]) ::NewRelic::Agent.logger.info('Deferring startup of agent reporting thread because ' \ "#{Agent.config[:dispatcher]} may fork.") true else false end end |