1
0
Fork 0
mirror of https://github.com/mperham/sidekiq.git synced 2022-11-09 13:52:34 -05:00

Switch airbrake to generic ExceptionHandler class and add support for ::Exceptional

This commit is contained in:
James Miller 2012-02-22 11:47:02 -08:00
parent 3317dbf0a0
commit 08a0c78581
2 changed files with 15 additions and 6 deletions

View file

@ -3,7 +3,7 @@ require 'sidekiq/util'
module Sidekiq module Sidekiq
module Middleware module Middleware
module Server module Server
class Airbrake class ExceptionHandler
include Util include Util
def call(*args) def call(*args)
yield yield
@ -11,20 +11,29 @@ module Sidekiq
logger.warn ex logger.warn ex
logger.warn ex.backtrace.join("\n") logger.warn ex.backtrace.join("\n")
send_to_airbrake(args[1], ex) if defined?(::Airbrake) send_to_airbrake(args[1], ex) if defined?(::Airbrake)
send_to_exceptional(args[1], ex) if defined?(::Exceptional)
raise raise
end end
private private
def send_to_airbrake(msg, ex) def send_to_airbrake(msg, ex)
logger.debug "Reporting error to Airbrake"
::Airbrake.notify(:error_class => ex.class.name, ::Airbrake.notify(:error_class => ex.class.name,
:error_message => "#{ex.class.name}: #{ex.message}", :error_message => "#{ex.class.name}: #{ex.message}",
:parameters => msg) :parameters => msg)
end end
def send_to_exceptional(msg, ex)
if ::Exceptional::Config.should_send_to_api?
logger.debug "Reporting error to Exceptional"
::Exceptional.context(msg)
::Exceptional::Remote.error(::Exceptional::ExceptionData.new(ex))
else
logger.debug "Not reporting error to Exceptional"
end
end
end end
end end
end end
end end

View file

@ -2,7 +2,7 @@ require 'celluloid'
require 'sidekiq/util' require 'sidekiq/util'
require 'sidekiq/middleware/server/active_record' require 'sidekiq/middleware/server/active_record'
require 'sidekiq/middleware/server/airbrake' require 'sidekiq/middleware/server/exception_handler'
require 'sidekiq/middleware/server/unique_jobs' require 'sidekiq/middleware/server/unique_jobs'
require 'sidekiq/middleware/server/failure_jobs' require 'sidekiq/middleware/server/failure_jobs'
@ -17,7 +17,7 @@ module Sidekiq
def self.default_middleware def self.default_middleware
Middleware::Chain.new do |m| Middleware::Chain.new do |m|
m.add Middleware::Server::Airbrake m.add Middleware::Server::ExceptionHandler
m.add Middleware::Server::UniqueJobs m.add Middleware::Server::UniqueJobs
m.add Middleware::Server::ActiveRecord m.add Middleware::Server::ActiveRecord
end end