Skip to content

Commit

Permalink
Merge pull request #441 from sharshenov/handle-all-exceptions
Browse files Browse the repository at this point in the history
Handle all exceptions
  • Loading branch information
michaelklishin authored Oct 7, 2020
2 parents f396a2d + c2843bf commit 5f8dedc
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions lib/sneakers/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,31 +72,31 @@ def process_work(delivery_info, metadata, msg, handler)
end
res = block_to_call.call(deserialized_msg, delivery_info, metadata, handler)
end
rescue StandardError, ScriptError => ex
rescue SignalException, SystemExit
# ServerEngine handles these exceptions, so they are not expected to be raised within the worker.
# Nevertheless, they are listed here to ensure that they are not caught by the rescue block below.
raise
rescue Exception => ex
res = :error
error = ex
worker_error(ex, log_msg: log_msg(msg), class: self.class.name,
message: msg, delivery_info: delivery_info, metadata: metadata)
end

if @should_ack

if res == :ack
ensure
if @should_ack
case res
# note to future-self. never acknowledge multiple (multiple=true) messages under threads.
handler.acknowledge(delivery_info, metadata, msg)
elsif res == :error
handler.error(delivery_info, metadata, msg, error)
elsif res == :reject
handler.reject(delivery_info, metadata, msg)
elsif res == :requeue
handler.reject(delivery_info, metadata, msg, true)
else
handler.noop(delivery_info, metadata, msg)
when :ack then handler.acknowledge(delivery_info, metadata, msg)
when :error then handler.error(delivery_info, metadata, msg, error)
when :reject then handler.reject(delivery_info, metadata, msg)
when :requeue then handler.reject(delivery_info, metadata, msg, true)
else
handler.noop(delivery_info, metadata, msg)
end
metrics.increment("work.#{self.class.name}.handled.#{res || 'noop'}")
end
metrics.increment("work.#{self.class.name}.handled.#{res || 'noop'}")
end

metrics.increment("work.#{self.class.name}.ended")
metrics.increment("work.#{self.class.name}.ended")
end
end

def stop
Expand Down

0 comments on commit 5f8dedc

Please sign in to comment.