From 33c043a4f8eeb962bd24e86ff4dc96567c2339bb Mon Sep 17 00:00:00 2001 From: Valentin Krasontovitsch Date: Tue, 5 Dec 2017 15:40:09 +0100 Subject: [PATCH 1/3] Add a base class to describe error handler interface --- lib/hutch/error_handlers/airbrake.rb | 4 ++-- lib/hutch/error_handlers/base.rb | 15 +++++++++++++++ lib/hutch/error_handlers/honeybadger.rb | 4 ++-- lib/hutch/error_handlers/logger.rb | 4 ++-- lib/hutch/error_handlers/opbeat.rb | 4 ++-- lib/hutch/error_handlers/sentry.rb | 4 ++-- 6 files changed, 25 insertions(+), 10 deletions(-) create mode 100644 lib/hutch/error_handlers/base.rb diff --git a/lib/hutch/error_handlers/airbrake.rb b/lib/hutch/error_handlers/airbrake.rb index caf256ea..782c4faf 100644 --- a/lib/hutch/error_handlers/airbrake.rb +++ b/lib/hutch/error_handlers/airbrake.rb @@ -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 diff --git a/lib/hutch/error_handlers/base.rb b/lib/hutch/error_handlers/base.rb new file mode 100644 index 00000000..8072d1b5 --- /dev/null +++ b/lib/hutch/error_handlers/base.rb @@ -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 diff --git a/lib/hutch/error_handlers/honeybadger.rb b/lib/hutch/error_handlers/honeybadger.rb index 0e677d16..eaf8d50b 100644 --- a/lib/hutch/error_handlers/honeybadger.rb +++ b/lib/hutch/error_handlers/honeybadger.rb @@ -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 diff --git a/lib/hutch/error_handlers/logger.rb b/lib/hutch/error_handlers/logger.rb index dbaa9803..85f0c0a6 100644 --- a/lib/hutch/error_handlers/logger.rb +++ b/lib/hutch/error_handlers/logger.rb @@ -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 diff --git a/lib/hutch/error_handlers/opbeat.rb b/lib/hutch/error_handlers/opbeat.rb index de9cddb1..119bf3ff 100644 --- a/lib/hutch/error_handlers/opbeat.rb +++ b/lib/hutch/error_handlers/opbeat.rb @@ -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) diff --git a/lib/hutch/error_handlers/sentry.rb b/lib/hutch/error_handlers/sentry.rb index 9465e37a..d5e25be4 100644 --- a/lib/hutch/error_handlers/sentry.rb +++ b/lib/hutch/error_handlers/sentry.rb @@ -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) From e15d8df87e6517738276c64480189b1377685a1f Mon Sep 17 00:00:00 2001 From: Valentin Krasontovitsch Date: Mon, 11 Dec 2017 12:21:16 +0100 Subject: [PATCH 2/3] Add test case for client setup error reporting --- spec/hutch/cli_spec.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/spec/hutch/cli_spec.rb b/spec/hutch/cli_spec.rb index 6ae6a0c6..515a6a45 100644 --- a/spec/hutch/cli_spec.rb +++ b/spec/hutch/cli_spec.rb @@ -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 From cd93891cb7d95af44d7de6b859e3bdaf32d29d04 Mon Sep 17 00:00:00 2001 From: Michael Klishin Date: Wed, 10 Jan 2018 16:07:45 +0300 Subject: [PATCH 3/3] Squash an RSpec warning --- spec/hutch/worker_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/hutch/worker_spec.rb b/spec/hutch/worker_spec.rb index c7578bc4..56c14487 100644 --- a/spec/hutch/worker_spec.rb +++ b/spec/hutch/worker_spec.rb @@ -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 }