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

Polish job failure notification

This commit is contained in:
Mike Perham 2018-01-15 10:39:32 -08:00
parent 32d03ecd52
commit a2db45bc0c
5 changed files with 17 additions and 5 deletions

View file

@ -159,6 +159,7 @@ module Sidekiq
def self.default_retries_exhausted=(prok)
logger.info { "default_retries_exhausted is deprecated, please use `config.failure_handlers << -> {|job, ex| }`" }
return nil unless prok
failure_handlers << prok
end

View file

@ -656,7 +656,7 @@ module Sidekiq
super 'dead'
end
def kill(message)
def kill(message, opts={})
now = Time.now.to_f
Sidekiq.redis do |conn|
conn.multi do
@ -665,6 +665,16 @@ module Sidekiq
conn.zremrangebyrank(name, 0, - self.class.max_jobs)
end
end
if opts[:notify_failure] != false
job = Sidekiq.load_json(message)
r = RuntimeError.new("Job killed by API")
r.set_backtrace(caller)
Sidekiq.failure_handlers.each do |handle|
handle.call(job, r)
end
end
true
end
def retry_all

View file

@ -192,7 +192,7 @@ module Sidekiq
def send_to_morgue(msg)
Sidekiq.logger.info { "Adding dead #{msg['class']} job #{msg['jid']}" }
payload = Sidekiq.dump_json(msg)
DeadSet.new.kill(payload)
DeadSet.new.kill(payload, notify_failure: false)
end
def retry_attempts_from(msg_retry, default)

View file

@ -157,7 +157,8 @@ module Sidekiq
job_hash = Sidekiq.load_json(jobstr)
rescue => ex
handle_exception(ex, { :context => "Invalid JSON for job", :jobstr => jobstr })
DeadSet.new.kill(jobstr)
# we can't notify because the job isn't a valid hash payload.
DeadSet.new.kill(jobstr, notify_failure: false)
ack = true
raise
end

View file

@ -320,11 +320,11 @@ class TestApi < Sidekiq::Test
end
it 'can kill a scheduled job' do
job_id = ApiWorker.perform_in(100, 1, 'jason')
job_id = ApiWorker.perform_in(100, 1, '{"foo":123}')
job = Sidekiq::ScheduledSet.new.find_job(job_id)
ds = Sidekiq::DeadSet.new
assert_equal 0, ds.size
refute_nil job.kill
job.kill
assert_equal 1, ds.size
end