Skip to content

Commit

Permalink
Auto log processor errors
Browse files Browse the repository at this point in the history
Fix 352
  • Loading branch information
Pablo Cantero committed Apr 10, 2017
1 parent 7a184a3 commit e75a712
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/shoryuken/manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ def stop(options = {})
end
end

def processor_failed(ex)
logger.error ex
logger.error ex.backtrace.join("\n") unless ex.backtrace.nil?
end

def processor_done(queue)
logger.debug { "Process done for '#{queue}'" }
end
Expand Down
3 changes: 3 additions & 0 deletions lib/shoryuken/processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ def process(queue, sqs_msg)
worker.class.server_middleware.invoke(worker, queue, sqs_msg, body) do
worker.perform(sqs_msg, body)
end
rescue Exception => ex
@manager.processor_failed(ex)
raise
ensure
@manager.processor_done(queue)
end
Expand Down
2 changes: 2 additions & 0 deletions spec/shoryuken/processor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def self.parse(*args)
end

it 'logs the error' do
expect(manager).to receive(:processor_failed)
expect(subject.logger).to receive(:error) do |&block|
expect(block.call).
to include("unexpected token at 'invalid json'\nbody_parser: json\nsqs_msg.body: invalid json")
Expand All @@ -108,6 +109,7 @@ def self.parse(*args)
end

it 're raises the error' do
expect(manager).to receive(:processor_failed)
expect { subject.process(queue, sqs_msg) }.
to raise_error(JSON::ParserError, /unexpected token at 'invalid json'/)
end
Expand Down

0 comments on commit e75a712

Please sign in to comment.