Sha256: 0021efa06931c978c2ee4e44f30a6f635dc35c1872d406b5f2414d37258f2d7a

Contents?: true

Size: 1.64 KB

Versions: 1

Compression:

Stored size: 1.64 KB

Contents

module Delayed::Plugins::AirbrakeExtended
  class Plugin < ::Delayed::Plugin
    module Notify
      def error(job, exception)
        # rescue if ExceptionNotifier fails for some reason
        begin
          # Default is to include the job_id
          params = {job_id: job.id}

          # But also include any instance variables set in the exception itself.
          #
          # The is the heart of things. I recommend using custom exception classes
          # which take the objects being worked on when the erorr is raised, and
          # stores them as instance variables. This means when an error occurs, you
          # get to see exactly which instance of a model was being worked on, and
          # exactly what that hash of updates consisted of. Much easier than just the
          # line number and message, or having to write custom begin/rescue/notifiy's
          # everywhere.
          #
          params.merge!(error.airbrake_params) if error.respond_to? :airbrake_params

          Airbrake.notify_or_ignore(error, parameters: params)

        rescue Exception => e
          Rails.logger.error "ExceptionNotifier failed: #{e.class.name}: #{e.message}"

          e.backtrace.each do |f|
            Rails.logger.error "  #{f}"
          end

          Rails.logger.flush
        end

        super if defined?(super)
      end
    end

    Rails.logger.info "Attaching Delayed::Plugins::AirbrakeExtended"

    callbacks do |lifecycle|
      lifecycle.before(:invoke_job) do |job|
        payload = job.payload_object
        payload = payload.object if payload.is_a? Delayed::PerformableMethod
        payload.extend Notify
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
airbrake-extended-0.0.4 lib/patches/delayed_plugin.rb