2014-02-24 23:47:44 -05:00
|
|
|
require 'sidekiq'
|
|
|
|
|
2012-07-31 11:43:09 -04:00
|
|
|
module Sidekiq
|
|
|
|
module ExceptionHandler
|
|
|
|
|
2014-02-24 23:47:44 -05:00
|
|
|
class Logger
|
|
|
|
def call(ex, ctxHash)
|
|
|
|
Sidekiq.logger.warn(ctxHash) if !ctxHash.empty?
|
2015-04-29 17:12:32 -04:00
|
|
|
Sidekiq.logger.warn "#{ex.class.name}: #{ex.message}"
|
2014-02-24 23:47:44 -05:00
|
|
|
Sidekiq.logger.warn ex.backtrace.join("\n") unless ex.backtrace.nil?
|
|
|
|
end
|
|
|
|
|
|
|
|
# Set up default handler which just logs the error
|
|
|
|
Sidekiq.error_handlers << Sidekiq::ExceptionHandler::Logger.new
|
|
|
|
end
|
|
|
|
|
2013-09-22 23:48:17 -04:00
|
|
|
def handle_exception(ex, ctxHash={})
|
2014-02-24 23:47:44 -05:00
|
|
|
Sidekiq.error_handlers.each do |handler|
|
|
|
|
begin
|
|
|
|
handler.call(ex, ctxHash)
|
|
|
|
rescue => ex
|
|
|
|
Sidekiq.logger.error "!!! ERROR HANDLER THREW AN ERROR !!!"
|
|
|
|
Sidekiq.logger.error ex
|
|
|
|
Sidekiq.logger.error ex.backtrace.join("\n") unless ex.backtrace.nil?
|
|
|
|
end
|
|
|
|
end
|
2012-07-31 11:43:09 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|