Skip to content

Commit

Permalink
refactor sidekiq handler
Browse files Browse the repository at this point in the history
  • Loading branch information
jjb committed Jan 8, 2015
1 parent 4cf88f7 commit 50c5c4f
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions lib/rollbar/sidekiq.rb
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
# encoding: utf-8

PARAM_BLACKLIST = ['backtrace', 'error_backtrace', 'error_message', 'error_class']
module Rollbar
PARAM_BLACKLIST = ['backtrace', 'error_backtrace', 'error_message', 'error_class']

if Sidekiq::VERSION < '3'
module Rollbar
class Sidekiq
def call(worker, msg, queue)
begin
yield
rescue Exception => e
params = msg.reject{ |k| PARAM_BLACKLIST.include?(k) }
scope = { :request => { :params => params } }
class SidekiqErrorHandler
def self.handle(scope, e, params)
params = msg.reject{ |k| PARAM_BLACKLIST.include?(k) }
scope = { :request => { :params => params } }

Rollbar.scope(scope).error(e)
raise
end
Rollbar.scope(scope).error(e)
end

def call(worker, msg, queue)
begin
yield
rescue Exception => e
SidekiqErrorHandler.handle(scope, e, params)
raise
end
end
end
end

Sidekiq.configure_server do |config|
Sidekiq.configure_server do |config|
if Sidekiq::VERSION < '3'
config.server_middleware do |chain|
chain.add Rollbar::Sidekiq
chain.add Rollbar::SidekiqErrorHandlingMiddleware
end
end
else
Sidekiq.configure_server do |config|
else
config.error_handlers << Proc.new do |e, context|
params = context.reject{ |k| PARAM_BLACKLIST.include?(k) }
scope = { :request => { :params => params } }

Rollbar.scope(scope).error(e)
SidekiqErrorHandler.handle(scope, e, params)
end
end
end

0 comments on commit 50c5c4f

Please sign in to comment.