lib/sidekiq/job_retry.rb in sidekiq-5.2.5 vs lib/sidekiq/job_retry.rb in sidekiq-5.2.6

- old
+ new

@@ -54,11 +54,12 @@ # include Sidekiq::Worker # sidekiq_options :retry => 10 # end # class JobRetry - class Skip < ::RuntimeError; end + class Handled < ::RuntimeError; end + class Skip < Handled; end include Sidekiq::Util DEFAULT_MAX_RETRY_ATTEMPTS = 25 @@ -69,11 +70,11 @@ # The global retry handler requires only the barest of data. # We want to be able to retry as much as possible so we don't # require the worker to be instantiated. def global(msg, queue) yield - rescue Skip => ex + rescue Handled => ex raise ex rescue Sidekiq::Shutdown => ey # ignore, will be pushed back onto queue during hard_shutdown raise ey rescue Exception => e @@ -90,11 +91,11 @@ handle_exception(handler_ex, { context: "Error calling death handler", job: msg }) end end end - raise e + raise Handled end # The local retry support means that any errors that occur within # this block can be associated with the given worker instance. @@ -104,11 +105,11 @@ # exception so the global block does not reprocess the error. The # Skip exception is unwrapped within Sidekiq::Processor#process before # calling the handle_exception handlers. def local(worker, msg, queue) yield - rescue Skip => ex + rescue Handled => ex raise ex rescue Sidekiq::Shutdown => ey # ignore, will be pushed back onto queue during hard_shutdown raise ey rescue Exception => e @@ -138,13 +139,11 @@ msg['retry_queue'] else queue end - # App code can stuff all sorts of crazy binary data into the error message - # that won't convert to JSON. - m = exception.message.to_s[0, 10_000] + m = exception_message(exception) if m.respond_to?(:scrub!) m.force_encoding("utf-8") m.scrub! end @@ -243,9 +242,21 @@ checked_causes << e.object_id return false if checked_causes.include?(e.cause.object_id) e.cause.instance_of?(Sidekiq::Shutdown) || exception_caused_by_shutdown?(e.cause, checked_causes) + end + + # Extract message from exception. + # Set a default if the message raises an error + def exception_message(exception) + begin + # App code can stuff all sorts of crazy binary data into the error message + # that won't convert to JSON. + exception.message.to_s[0, 10_000] + rescue + "!!! ERROR MESSAGE THREW AN ERROR !!!".dup + end end end end