class ScoutApm::BackgroundJobIntegrations::Resque
Public Instance Methods
forking?()
click to toggle source
Lies. This forks really aggressively, but we have to do handling of it manually here, rather than via any sort of automatic background worker starting
# File lib/scout_apm/background_job_integrations/resque.rb, line 17 def forking? false end
inject_job_instrument()
click to toggle source
Insert ourselves into the point when resque turns a string “TestJob” into the class constant TestJob, and insert our instrumentation plugin into that constantized class
This automates away any need for the user to insert our instrumentation into each of their jobs
# File lib/scout_apm/background_job_integrations/resque.rb, line 60 def inject_job_instrument ::Resque::Job.class_eval do def payload_class_with_scout_instruments klass = payload_class_without_scout_instruments klass.extend(ScoutApm::Instruments::Resque) klass end alias_method :payload_class_without_scout_instruments, :payload_class alias_method :payload_class, :payload_class_with_scout_instruments end end
install()
click to toggle source
# File lib/scout_apm/background_job_integrations/resque.rb, line 21 def install install_before_fork install_after_fork end
install_after_fork()
click to toggle source
# File lib/scout_apm/background_job_integrations/resque.rb, line 43 def install_after_fork ::Resque.after_fork do begin ScoutApm::Agent.instance.context.become_remote_client!(bind, port) inject_job_instrument rescue => e ScoutApm::Agent.instance.context.logger.warn "Error while Installing Resque after_fork: #{e.inspect}" end end end
install_before_fork()
click to toggle source
# File lib/scout_apm/background_job_integrations/resque.rb, line 26 def install_before_fork ::Resque.before_first_fork do begin if ScoutApm::Agent.instance.context.config.value('start_resque_server_instrument') ScoutApm::Agent.instance.start ScoutApm::Agent.instance.context.start_remote_server!(bind, port) else logger.info("Not starting remote server due to 'start_resque_server_instrument' setting") end rescue Errno::EADDRINUSE ScoutApm::Agent.instance.context.logger.warn "Error while Installing Resque Instruments, Port #{port} already in use. Set via the `remote_agent_port` configuration option" rescue => e ScoutApm::Agent.instance.context.logger.warn "Error while Installing Resque before_first_fork: #{e.inspect}" end end end
name()
click to toggle source
# File lib/scout_apm/background_job_integrations/resque.rb, line 4 def name :resque end
payload_class_with_scout_instruments()
click to toggle source
# File lib/scout_apm/background_job_integrations/resque.rb, line 62 def payload_class_with_scout_instruments klass = payload_class_without_scout_instruments klass.extend(ScoutApm::Instruments::Resque) klass end
present?()
click to toggle source
# File lib/scout_apm/background_job_integrations/resque.rb, line 8 def present? defined?(::Resque) && ::Resque.respond_to?(:before_first_fork) && ::Resque.respond_to?(:after_fork) end
Private Instance Methods
bind()
click to toggle source
# File lib/scout_apm/background_job_integrations/resque.rb, line 74 def bind config.value("remote_agent_host") end
config()
click to toggle source
# File lib/scout_apm/background_job_integrations/resque.rb, line 82 def config @config || ScoutApm::Agent.instance.context.config end
port()
click to toggle source
# File lib/scout_apm/background_job_integrations/resque.rb, line 78 def port config.value("remote_agent_port") end