Class: ScoutApm::BackgroundJobIntegrations::Resque
- Inherits:
-
Object
- Object
- ScoutApm::BackgroundJobIntegrations::Resque
- Defined in:
- lib/scout_apm/background_job_integrations/resque.rb
Instance Method Summary collapse
-
#forking? ⇒ Boolean
Lies.
-
#inject_job_instrument ⇒ Object
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.
- #install ⇒ Object
- #install_after_fork ⇒ Object
- #install_before_fork ⇒ Object
- #name ⇒ Object
- #present? ⇒ Boolean
Instance Method Details
#forking? ⇒ Boolean
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
17 18 19 |
# File 'lib/scout_apm/background_job_integrations/resque.rb', line 17 def forking? false end |
#inject_job_instrument ⇒ Object
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
60 61 62 63 64 65 66 67 68 69 70 |
# 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 ⇒ Object
21 22 23 24 |
# File 'lib/scout_apm/background_job_integrations/resque.rb', line 21 def install install_before_fork install_after_fork end |
#install_after_fork ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# 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 ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# 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 ⇒ Object
4 5 6 |
# File 'lib/scout_apm/background_job_integrations/resque.rb', line 4 def name :resque end |
#present? ⇒ Boolean
8 9 10 11 12 |
# 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 |