Sha256: 589166724bc1db8011b6a1b914b4c25ff96f15ed1177aa9c04fd9811cf00f8d5

Contents?: true

Size: 1.73 KB

Versions: 13

Compression:

Stored size: 1.73 KB

Contents

require "resque"
require "resque/failure/multiple"

module Bugsnag
  class Resque < ::Resque::Failure::Base

    FRAMEWORK_ATTRIBUTES = {
      :framework => "Resque"
    }

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

    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

    def save
      Bugsnag.notify(exception, true) do |report|
        report.severity = "error"
        report.severity_reason = {
          :type => Bugsnag::Report::UNHANDLED_EXCEPTION_MIDDLEWARE,
          :attributes => FRAMEWORK_ATTRIBUTES
        }
        report.meta_data.merge!({:context => "#{payload['class']}@#{queue}", :payload => payload})
      end
    end
  end
end

# For backwards compatibility
Resque::Failure::Bugsnag = Bugsnag::Resque

# Auto-load the failure backend
Bugsnag::Resque.add_failure_backend

if Resque::Worker.new(:bugsnag_fork_check).fork_per_job?
  Resque.after_fork do
    Bugsnag.configuration.app_type = "resque"
    Bugsnag.configuration.default_delivery_method = :synchronous
  end
else
  Resque.before_first_fork do
    Bugsnag.configuration.app_type = "resque"
    Bugsnag.configuration.default_delivery_method = :synchronous
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
bugsnag-6.6.3 lib/bugsnag/integrations/resque.rb
bugsnag-6.6.2 lib/bugsnag/integrations/resque.rb
bugsnag-6.6.1 lib/bugsnag/integrations/resque.rb
bugsnag-6.6.0 lib/bugsnag/integrations/resque.rb
bugsnag-6.5.0 lib/bugsnag/integrations/resque.rb
bugsnag-6.4.0 lib/bugsnag/integrations/resque.rb
bugsnag-6.3.0 lib/bugsnag/integrations/resque.rb
bugsnag-6.3.0.beta.0 lib/bugsnag/integrations/resque.rb
bugsnag-6.2.0 lib/bugsnag/integrations/resque.rb
bugsnag-6.1.1 lib/bugsnag/integrations/resque.rb
bugsnag-6.1.0 lib/bugsnag/integrations/resque.rb
bugsnag-6.0.1 lib/bugsnag/integrations/resque.rb
bugsnag-6.0.0 lib/bugsnag/integrations/resque.rb