Class: Appsignal::Hooks::ActiveJobHook Private

Inherits:
Hook show all
Defined in:
lib/appsignal/hooks/active_job.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Defined Under Namespace

Modules: ActiveJobClassInstrumentation, ActiveJobHelpers

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Hook

#initialize, #installed?, register, #try_to_install

Constructor Details

This class inherits a constructor from Appsignal::Hooks::Hook

Class Method Details

.dependencies_present?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


20
21
22
# File 'lib/appsignal/hooks/active_job.rb', line 20

def self.dependencies_present?
  defined?(::ActiveJob)
end

.version_7_1_or_higher?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


9
10
11
12
13
14
15
16
17
18
# File 'lib/appsignal/hooks/active_job.rb', line 9

def self.version_7_1_or_higher?
  @version_7_1_or_higher ||=
    if dependencies_present?
      major = ::ActiveJob::VERSION::MAJOR
      minor = ::ActiveJob::VERSION::MINOR
      major > 7 || (major == 7 && minor >= 1)
    else
      false
    end
end

Instance Method Details

#dependencies_present?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


24
25
26
# File 'lib/appsignal/hooks/active_job.rb', line 24

def dependencies_present?
  self.class.dependencies_present?
end

#installObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/appsignal/hooks/active_job.rb', line 28

def install
  ActiveSupport.on_load(:active_job) do
    ::ActiveJob::Base
      .extend ::Appsignal::Hooks::ActiveJobHook::ActiveJobClassInstrumentation

    next unless Appsignal::Hooks::ActiveJobHook.version_7_1_or_higher?

    # Only works on Active Job 7.1 and newer
    ::ActiveJob::Base.after_discard do |_job, exception|
      next unless Appsignal.config[:activejob_report_errors] == "discard"

      Appsignal::Transaction.current.set_error(exception)
    end
  end
end