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
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/scout_apm/background_job_integrations/resque.rb', line 57 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
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/scout_apm/background_job_integrations/resque.rb', line 40 def install_after_fork ::Resque.after_fork do begin ScoutApm::Agent.instance.use_remote_recorder(bind, port) inject_job_instrument rescue => e ScoutApm::Agent.instance.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 |
# File 'lib/scout_apm/background_job_integrations/resque.rb', line 26 def install_before_fork ::Resque.before_first_fork do begin ScoutApm::Agent.instance.start(:skip_app_server_check => true) ScoutApm::Agent.instance.start_background_worker ScoutApm::Agent.instance.start_remote_server(bind, port) rescue Errno::EADDRINUSE ScoutApm::Agent.instance.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.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 |