Skip to content

Commit

Permalink
Merge branch 'master' of github.com:mperham/sidekiq
Browse files Browse the repository at this point in the history
  • Loading branch information
mperham committed Sep 7, 2014
2 parents 1867c79 + 5863a02 commit 9ae598d
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions lib/sidekiq/middleware/server/retry_jobs.rb
Expand Up @@ -80,6 +80,12 @@ def call(worker, msg, queue)
raise Sidekiq::Shutdown if exception_caused_by_shutdown?(e)

raise e unless msg['retry']
attempt_retry(worker, msg, queue, e)
end

private

def attempt_retry(worker, msg, queue, exception)
max_retry_attempts = retry_attempts_from(msg['retry'], @max_retries)

msg['queue'] = if msg['retry_queue']
Expand All @@ -90,14 +96,14 @@ def call(worker, msg, queue)

# App code can stuff all sorts of crazy binary data into the error message
# that won't convert to JSON.
m = e.message[0..10_000]
m = exception.message[0..10_000]
if m.respond_to?(:scrub!)
m.force_encoding("utf-8")
m.scrub!
end

msg['error_message'] = m
msg['error_class'] = e.class.name
msg['error_class'] = exception.class.name
count = if msg['retry_count']
msg['retried_at'] = Time.now.to_f
msg['retry_count'] += 1
Expand All @@ -107,11 +113,11 @@ def call(worker, msg, queue)
end

if msg['backtrace'] == true
msg['error_backtrace'] = e.backtrace
msg['error_backtrace'] = exception.backtrace
elsif msg['backtrace'] == false
# do nothing
elsif msg['backtrace'].to_i != 0
msg['error_backtrace'] = e.backtrace[0..msg['backtrace'].to_i]
msg['error_backtrace'] = exception.backtrace[0..msg['backtrace'].to_i]
end

if count < max_retry_attempts
Expand All @@ -127,11 +133,9 @@ def call(worker, msg, queue)
retries_exhausted(worker, msg)
end

raise e
raise exception
end

private

def retries_exhausted(worker, msg)
logger.debug { "Dropping message after hitting the retry maximum: #{msg}" }
begin
Expand Down

0 comments on commit 9ae598d

Please sign in to comment.