mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Make error handler change fully backwards compatible
The change that Fixes mperham/sidekiq#3673 actually broke any existing exception handlers due to differences in expected parameter count. This fixes it explicitly which normally seems like it won't matter but there are random monitoring gems that install their own sidekiq exception handlers that I don't want to break.
This commit is contained in:
parent
58d5ff1e6d
commit
aead218b84
2 changed files with 35 additions and 2 deletions
|
@ -24,7 +24,13 @@ module Sidekiq
|
|||
def handle_exception(ex, ctxHash={}, options={})
|
||||
Sidekiq.error_handlers.each do |handler|
|
||||
begin
|
||||
handler.call(ex, ctxHash, options)
|
||||
arity = handler.method(:call).arity
|
||||
# new-style three argument method or fully variable arguments
|
||||
if arity == -3 || arity == -1
|
||||
handler.call(ex, ctxHash, options)
|
||||
else
|
||||
handler.call(ex, ctxHash)
|
||||
end
|
||||
rescue => ex
|
||||
Sidekiq.logger.error "!!! ERROR HANDLER THREW AN ERROR !!!"
|
||||
Sidekiq.logger.error ex
|
||||
|
@ -32,6 +38,5 @@ module Sidekiq
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -141,6 +141,34 @@ class TestProcessor < Sidekiq::Test
|
|||
assert_instance_of StandardError, errors.last[:exception]
|
||||
assert_equal :error, errors.last[:options][:level]
|
||||
end
|
||||
|
||||
class TestHandler
|
||||
attr_reader :count
|
||||
|
||||
def initialize
|
||||
@count = 0
|
||||
end
|
||||
|
||||
def call(exc, ctx)
|
||||
@count += 1
|
||||
end
|
||||
end
|
||||
|
||||
it 'can call two argument exception handlers' do
|
||||
handler = TestHandler.new
|
||||
Sidekiq.error_handlers << handler
|
||||
job_hash = { 'class' => MockWorker.to_s, 'args' => ['boom'] }
|
||||
msg = Sidekiq.dump_json(job_hash)
|
||||
@processor.instance_variable_set(:'@reloader', proc { raise TEST_EXCEPTION })
|
||||
job = work(msg)
|
||||
begin
|
||||
@processor.instance_variable_set(:'@job', job)
|
||||
@processor.process(job)
|
||||
rescue TestException
|
||||
end
|
||||
assert_equal 1, handler.count
|
||||
Sidekiq.error_handlers.pop
|
||||
end
|
||||
end
|
||||
|
||||
describe 'acknowledgement' do
|
||||
|
|
Loading…
Add table
Reference in a new issue