mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Call 'exhausted' worker method after retries
When the maximum number of retries is hit and the message is about to be thrown away, give the option of allowing the worker to say goodbye by defining an 'exhausted' method on the worker.
This commit is contained in:
parent
d54422b14e
commit
172434d459
2 changed files with 16 additions and 1 deletions
|
@ -14,7 +14,8 @@ module Sidekiq
|
|||
# 3. after a few days, a developer deploys a fix. the message is
|
||||
# reprocessed successfully.
|
||||
# 4. if 3 never happens, sidekiq will eventually give up and throw the
|
||||
# message away.
|
||||
# message away. If the worker defines a method called 'exhausted', this
|
||||
# will be called before throwing the message away.
|
||||
#
|
||||
# A message looks like:
|
||||
#
|
||||
|
@ -82,8 +83,10 @@ 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}" }
|
||||
end
|
||||
|
||||
raise e
|
||||
end
|
||||
|
||||
|
|
|
@ -167,6 +167,18 @@ class TestRetry < MiniTest::Unit::TestCase
|
|||
# MiniTest can't assert that a method call did NOT happen!?
|
||||
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
|
||||
assert_raises RuntimeError do
|
||||
handler.call(worker, msg, 'default') do
|
||||
raise "kerblammo!"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'poller' do
|
||||
|
|
Loading…
Reference in a new issue