2012-02-14 12:00:26 -05:00
|
|
|
require 'sidekiq/util'
|
|
|
|
|
2012-02-08 20:04:19 -05:00
|
|
|
module Sidekiq
|
|
|
|
module Middleware
|
|
|
|
module Server
|
2012-02-22 14:47:02 -05:00
|
|
|
class ExceptionHandler
|
2012-02-14 12:00:26 -05:00
|
|
|
include Util
|
2012-02-11 02:16:12 -05:00
|
|
|
def call(*args)
|
2012-02-08 20:04:19 -05:00
|
|
|
yield
|
|
|
|
rescue => ex
|
2012-02-14 12:00:26 -05:00
|
|
|
logger.warn ex
|
|
|
|
logger.warn ex.backtrace.join("\n")
|
2012-02-11 02:16:12 -05:00
|
|
|
send_to_airbrake(args[1], ex) if defined?(::Airbrake)
|
2012-02-22 14:47:02 -05:00
|
|
|
send_to_exceptional(args[1], ex) if defined?(::Exceptional)
|
2012-02-27 02:36:59 -05:00
|
|
|
send_to_exception_notifier(args[1], ex) if defined?(::ExceptionNotifier)
|
2012-02-08 20:04:19 -05:00
|
|
|
raise
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def send_to_airbrake(msg, ex)
|
2012-02-27 10:08:26 -05:00
|
|
|
::Airbrake.notify(ex, :parameters => msg)
|
2012-02-08 20:04:19 -05:00
|
|
|
end
|
2012-02-22 14:47:02 -05:00
|
|
|
|
|
|
|
def send_to_exceptional(msg, ex)
|
|
|
|
if ::Exceptional::Config.should_send_to_api?
|
|
|
|
::Exceptional.context(msg)
|
|
|
|
::Exceptional::Remote.error(::Exceptional::ExceptionData.new(ex))
|
|
|
|
end
|
|
|
|
end
|
2012-02-27 02:36:59 -05:00
|
|
|
|
|
|
|
def send_to_exception_notifier(msg, ex)
|
2012-02-27 10:08:26 -05:00
|
|
|
::ExceptionNotifier::Notifier.background_exception_notification(ex, :data => { :message => msg })
|
2012-02-27 02:36:59 -05:00
|
|
|
end
|
2012-02-08 20:04:19 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|