Sha256: 19ba052384f66f887bfe78a51787edfe774a66de77009ade6199b05c1314ca6c

Contents?: true

Size: 1.42 KB

Versions: 3

Compression:

Stored size: 1.42 KB

Contents

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

module Bugsnag
  class Resque < ::Resque::Failure::Base
    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.auto_notify(exception, {:context => "#{payload['class']}@#{queue}", :payload => payload})
    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

3 entries across 3 versions & 1 rubygems

Version Path
bugsnag-5.3.3 lib/bugsnag/resque.rb
bugsnag-5.3.2 lib/bugsnag/resque.rb
bugsnag-5.3.1 lib/bugsnag/resque.rb