1
0
Fork 0
mirror of https://github.com/mperham/sidekiq.git synced 2022-11-09 13:52:34 -05:00

'exhausted' changed to 'retries_exhausted'

Additionally, any errors raised during retries_exhausted hook
are logged and dropped before resuming original control flow.
This commit is contained in:
James Kassemi 2013-03-21 12:16:07 -06:00
parent 172434d459
commit 5824857b59
2 changed files with 33 additions and 10 deletions

View file

@ -83,13 +83,20 @@ module Sidekiq
end
else
# Goodbye dear message, you (re)tried your best I'm sure.
worker.exhausted(*msg['args']) if worker.respond_to?(:exhausted)
logger.debug { "Dropping message after hitting the retry maximum: #{msg}" }
retries_exhausted(msg)
end
raise e
end
def retries_exhausted(msg)
logger.debug { "Dropping message after hitting the retry maximum: #{msg}" }
worker.retries_exhausted(*msg['args']) if worker.respond_to?(:retries_exhausted)
rescue Exception => e
logger.debug { "Failure during `retries_exhausted` hook: #{e} - #{msg}" }
end
def retry_attempts_from(msg_retry, default)
if msg_retry.is_a?(Fixnum)
msg_retry

View file

@ -168,14 +168,30 @@ class TestRetry < MiniTest::Unit::TestCase
assert_raises(MockExpectationError) { @redis.verify }
end
it 'calls exhausted method on worker after too many retries if available' do
msg = {"class"=>"Bob", "args"=>[1, 2, "foo"], "queue"=>"default", "error_message"=>"kerblammo!", "error_class"=>"RuntimeError", "failed_at"=>Time.now.utc, "retry"=>3, "retry_count"=>3}
worker = MiniTest::Mock.new
worker.expect :exhausted, true, [1, 2, "foo"]
handler = Sidekiq::Middleware::Server::RetryJobs.new
describe "retry exhaustion" do
let(:worker){ MiniTest::Mock.new }
let(:handler){ Sidekiq::Middleware::Server::RetryJobs.new }
let(:msg){ {"class"=>"Bob", "args"=>[1, 2, "foo"], "queue"=>"default", "error_message"=>"kerblammo!", "error_class"=>"RuntimeError", "failed_at"=>Time.now.utc, "retry"=>3, "retry_count"=>3} }
it 'calls worker retries_exhausted after too many retries' do
worker.expect(:retries_exhausted, true, [1,2,3])
task_misbehaving_worker
end
it 'handles and logs retries_exhausted failures gracefully (drops them)' do
def worker.retries_exhausted(*args)
raise 'bam!'
end
e = task_misbehaving_worker
assert_equal e.message, "kerblammo!"
end
def task_misbehaving_worker
assert_raises RuntimeError do
handler.call(worker, msg, 'default') do
raise "kerblammo!"
handler.call('', msg, 'default') do
raise 'kerblammo!'
end
end
end
end