Skip to content

Commit

Permalink
Merge branch 'valentin-krasontovitsch-288_add_error_handler_class'
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelklishin committed Jan 10, 2018
2 parents e244391 + cd93891 commit 47632a0
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 11 deletions.
4 changes: 2 additions & 2 deletions lib/hutch/error_handlers/airbrake.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
require 'hutch/logging'
require 'airbrake'
require 'hutch/error_handlers/base'

module Hutch
module ErrorHandlers
class Airbrake
include Logging
class Airbrake < Base

def handle(properties, payload, consumer, ex)
message_id = properties.message_id
Expand Down
15 changes: 15 additions & 0 deletions lib/hutch/error_handlers/base.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Hutch
module ErrorHandlers
class Base
include Logging

def handle(properties, payload, consumer, ex)
raise NotImplementedError.new
end

def handle_setup_exception(ex)
raise NotImplementedError.new
end
end
end
end
4 changes: 2 additions & 2 deletions lib/hutch/error_handlers/honeybadger.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
require 'hutch/logging'
require 'honeybadger'
require 'hutch/error_handlers/base'

module Hutch
module ErrorHandlers
# Error handler for the Honeybadger.io service
class Honeybadger
include Logging
class Honeybadger < Base

def handle(properties, payload, consumer, ex)
message_id = properties.message_id
Expand Down
4 changes: 2 additions & 2 deletions lib/hutch/error_handlers/logger.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require 'hutch/logging'
require 'hutch/error_handlers/base'

module Hutch
module ErrorHandlers
class Logger
include Logging
class Logger < ErrorHandlers::Base

def handle(properties, payload, consumer, ex)
message_id = properties.message_id
Expand Down
4 changes: 2 additions & 2 deletions lib/hutch/error_handlers/opbeat.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
require 'hutch/logging'
require 'opbeat'
require 'hutch/error_handlers/base'

module Hutch
module ErrorHandlers
class Opbeat
include Logging
class Opbeat < Base

def initialize
unless ::Opbeat.respond_to?(:report)
Expand Down
4 changes: 2 additions & 2 deletions lib/hutch/error_handlers/sentry.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
require 'hutch/logging'
require 'raven'
require 'hutch/error_handlers/base'

module Hutch
module ErrorHandlers
class Sentry
include Logging
class Sentry < Base

def initialize
unless Raven.respond_to?(:capture_exception)
Expand Down
13 changes: 13 additions & 0 deletions spec/hutch/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@
describe Hutch::CLI do
let(:cli) { Hutch::CLI.new }

describe "#start_work_loop" do
context "connection error during setup" do
let(:error) { Hutch::ConnectionError.new }
it "gets reported using error handlers" do
allow(Hutch).to receive(:connect).and_raise(error)
Hutch::Config[:error_handlers].each do |backend|
expect(backend).to receive(:handle_setup_exception).with(error)
end
cli.start_work_loop
end
end
end

describe "#parse_options" do
context "--config" do
context "when the config file does not exist" do
Expand Down
2 changes: 1 addition & 1 deletion spec/hutch/worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
it 'requeues the message' do
allow(consumer_instance).to receive(:process).and_raise('failed')
requeuer = double
allow(requeuer).to receive(:handle).ordered { |delivery_info, properties, broker, e|
allow(requeuer).to receive(:handle) { |delivery_info, properties, broker, e|
broker.requeue delivery_info.delivery_tag
true
}
Expand Down

0 comments on commit 47632a0

Please sign in to comment.