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:
parent
172434d459
commit
5824857b59
2 changed files with 33 additions and 10 deletions
|
@ -83,13 +83,20 @@ module Sidekiq
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
# Goodbye dear message, you (re)tried your best I'm sure.
|
# Goodbye dear message, you (re)tried your best I'm sure.
|
||||||
worker.exhausted(*msg['args']) if worker.respond_to?(:exhausted)
|
retries_exhausted(msg)
|
||||||
logger.debug { "Dropping message after hitting the retry maximum: #{msg}" }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
raise e
|
raise e
|
||||||
end
|
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)
|
def retry_attempts_from(msg_retry, default)
|
||||||
if msg_retry.is_a?(Fixnum)
|
if msg_retry.is_a?(Fixnum)
|
||||||
msg_retry
|
msg_retry
|
||||||
|
|
|
@ -168,14 +168,30 @@ class TestRetry < MiniTest::Unit::TestCase
|
||||||
assert_raises(MockExpectationError) { @redis.verify }
|
assert_raises(MockExpectationError) { @redis.verify }
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'calls exhausted method on worker after too many retries if available' do
|
describe "retry exhaustion" 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}
|
let(:worker){ MiniTest::Mock.new }
|
||||||
worker = MiniTest::Mock.new
|
let(:handler){ Sidekiq::Middleware::Server::RetryJobs.new }
|
||||||
worker.expect :exhausted, true, [1, 2, "foo"]
|
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} }
|
||||||
handler = Sidekiq::Middleware::Server::RetryJobs.new
|
|
||||||
assert_raises RuntimeError do
|
it 'calls worker retries_exhausted after too many retries' do
|
||||||
handler.call(worker, msg, 'default') do
|
worker.expect(:retries_exhausted, true, [1,2,3])
|
||||||
raise "kerblammo!"
|
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('', msg, 'default') do
|
||||||
|
raise 'kerblammo!'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue