2015-12-31 18:33:35 -05:00
|
|
|
# frozen_string_literal: true
|
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
|
2017-11-29 19:23:49 -05:00
|
|
|
def call(ex, ctxHash)
|
|
|
|
Sidekiq.logger.warn(Sidekiq.dump_json(ctxHash)) if !ctxHash.empty?
|
|
|
|
Sidekiq.logger.warn("#{ex.class.name}: #{ex.message}")
|
|
|
|
Sidekiq.logger.warn(ex.backtrace.join("\n")) unless ex.backtrace.nil?
|
2014-02-24 23:47:44 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
Sidekiq.error_handlers << Sidekiq::ExceptionHandler::Logger.new
|
|
|
|
end
|
|
|
|
|
2017-11-29 19:23:49 -05:00
|
|
|
def handle_exception(ex, ctxHash={})
|
2014-02-24 23:47:44 -05:00
|
|
|
Sidekiq.error_handlers.each do |handler|
|
|
|
|
begin
|
2017-11-29 19:23:49 -05:00
|
|
|
handler.call(ex, ctxHash)
|
2014-02-24 23:47:44 -05:00
|
|
|
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
|