Class: ScoutApm::BackgroundJobIntegrations::Resque

Inherits:
Object
  • Object
show all
Defined in:
lib/scout_apm/background_job_integrations/resque.rb

Instance Method Summary collapse

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

Returns:

  • (Boolean)


16
17
18
# File 'lib/scout_apm/background_job_integrations/resque.rb', line 16

def forking?
  false
end

#installObject



20
21
22
23
# File 'lib/scout_apm/background_job_integrations/resque.rb', line 20

def install
  install_before_first_fork
  install_instruments
end

#install_before_first_forkObject



25
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 25

def install_before_first_fork
  ::Resque.before_first_fork do
    begin
      # Don't check fork_per_job here in case some workers fork_per_job and some don't.
      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
      logger.warn "Error while Installing Resque Instruments, Port #{port} already in use. Set via the `remote_agent_port` configuration option"
    rescue => e
      logger.warn "Error while Installing Resque before_first_fork: #{e.inspect}"
    end
  end
end

#install_instrumentsObject



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/scout_apm/background_job_integrations/resque.rb', line 43

def install_instruments
  ::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

#nameObject



4
5
6
# File 'lib/scout_apm/background_job_integrations/resque.rb', line 4

def name
  :resque
end

#present?Boolean

Returns:

  • (Boolean)


8
9
10
11
# File 'lib/scout_apm/background_job_integrations/resque.rb', line 8

def present?
  defined?(::Resque) &&
    ::Resque.respond_to?(:before_first_fork)
end