From 8c53356fc8e6ff24ba739fed70a81d3c0ad0d907 Mon Sep 17 00:00:00 2001 From: Nate Berkopec Date: Mon, 26 Sep 2016 14:51:13 -0600 Subject: [PATCH] Provide consistent interface to exception handlers (#3161) This commit ensures that exception handlers are always provided with two objects: * The Exception * A hash with the following keys: * `:context` (Required) - A String message explaining what happened * `:job` (Optional) - If this occurred while a job was being processed, this is the deserialized job Hash * `:jobstr` (Optional) - If this occurred during job deserialization, this is the raw JSON string of the job * `:event` (Optional) - If this occurred during a lifecycle event, name of the event --- lib/sidekiq/processor.rb | 2 +- lib/sidekiq/util.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/sidekiq/processor.rb b/lib/sidekiq/processor.rb index 6a346907..44c80027 100644 --- a/lib/sidekiq/processor.rb +++ b/lib/sidekiq/processor.rb @@ -143,7 +143,7 @@ module Sidekiq # we didn't properly finish it. ack = false rescue Exception => ex - handle_exception(ex, job || { :job => jobstr }) + handle_exception(ex, { :context => "Job raised exception", :job => job, :jobstr => jobstr }) raise ensure work.acknowledge if ack diff --git a/lib/sidekiq/util.rb b/lib/sidekiq/util.rb index d16272dc..17ec1763 100644 --- a/lib/sidekiq/util.rb +++ b/lib/sidekiq/util.rb @@ -53,7 +53,7 @@ module Sidekiq begin block.call rescue => ex - handle_exception(ex, { event: event }) + handle_exception(ex, { context: "Exception during Sidekiq lifecycle event.", event: event }) end end arr.clear