Class: Bugsnag::Resque

Inherits:
Resque::Failure::Base
  • Object
show all
Defined in:
lib/bugsnag/integrations/resque.rb

Constant Summary collapse

FRAMEWORK_ATTRIBUTES =
{
  :framework => "Resque"
}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.add_failure_backendObject

Sets up the Resque failure backend.


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/bugsnag/integrations/resque.rb', line 20

def self.add_failure_backend
  return if ::Resque::Failure.backend == self

  # Ensure resque is using a "Multiple" failure backend
  unless ::Resque::Failure.backend < ::Resque::Failure::Multiple
    original_backend = ::Resque::Failure.backend
    ::Resque::Failure.backend = ::Resque::Failure::Multiple
    ::Resque::Failure.backend.classes ||= []
    ::Resque::Failure.backend.classes << original_backend
  end

  # Add Bugsnag failure backend
  unless ::Resque::Failure.backend.classes.include?(self)
    ::Resque::Failure.backend.classes << self
  end
end

.configure(&block) ⇒ Object

Callthrough to Bugsnag configuration.


13
14
15
16
# File 'lib/bugsnag/integrations/resque.rb', line 13

def self.configure(&block)
  add_failure_backend
  Bugsnag.configure(&block)
end

Instance Method Details

#saveObject

Notifies Bugsnag of a raised exception.


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/bugsnag/integrations/resque.rb', line 39

def save
  Bugsnag.notify(exception, true) do |report|
    report.severity = "error"
    report.severity_reason = {
      :type => Bugsnag::Report::UNHANDLED_EXCEPTION_MIDDLEWARE,
      :attributes => FRAMEWORK_ATTRIBUTES
    }

     = payload
    class_name = ['class']

    # when using Active Job the payload "class" will always be the Resque
    # "JobWrapper", so we need to unwrap the actual class name
    if class_name == "ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper"
      unwrapped_class_name = ['args'][0]['job_class'] rescue nil

      if unwrapped_class_name
        class_name = unwrapped_class_name
        ['wrapped'] ||= unwrapped_class_name
      end
    end

    context = "#{class_name}@#{queue}"
    report..merge!({ context: context, payload:  })
    report.automatic_context = context
  end
end