hutch 0.22.1 → 0.23.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a331137bca776d401e85057a0caa84922dda9d1d
4
- data.tar.gz: c677873d07dfad4a6be14574d413e3870febb1bd
3
+ metadata.gz: 121ef2c74885824fb6289f89e89e55cb2e83f577
4
+ data.tar.gz: de5ed49d8ad6e020bdfde9e5b39ecadda276dedf
5
5
  SHA512:
6
- metadata.gz: dd21d047618cf83c463b7064042270d2886d7cc232c9d1234b542912e37e7250f8a700fb47fcdc62f31ab61789a4fc3f89f3946387187081d0c705f0024d0ffe
7
- data.tar.gz: bee9c047725370823d44a5a392e1544559998d70c36b7b084d6ba7f8cf93907f822d2ce935c024d51a3c4cfb567d1a68ab402bde62b30f497a67d4df85edac43
6
+ metadata.gz: 81050d31cea806c918a51a952c8b1b695c384f0d0dd7beb1a89e01af2183c5fdfcc819a62289f7de4afa3a8ddfbb7df1801e935fae4904404e4aee1cf66e34e4
7
+ data.tar.gz: 0008ef900bf621471fee3cbd4e5c753d3c9d271f3c6fe2f18971586d6c72477f1862dfa55131a3a4b98e0cf0acdfb3d2396d7f54007c76c4fded7067abdc0329
data/.gitignore CHANGED
@@ -7,3 +7,4 @@ Gemfile.lock
7
7
  coverage
8
8
  .yardoc
9
9
  doc
10
+ gemfiles/Gemfile.*.lock
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --order random
data/.travis.yml CHANGED
@@ -1,17 +1,21 @@
1
1
  language: ruby
2
2
  cache: bundler
3
- rvm:
4
- - "2.3.0"
5
- - "2.2"
6
- - "2.1"
7
- - "2.0"
8
- - "jruby-9.0.0.0"
9
-
10
- sudo: false
3
+ before_install: gem i bundler
4
+ matrix:
5
+ include:
6
+ - rvm: 2.3.0
7
+ gemfile: gemfiles/Gemfile.activesupport5
8
+ - rvm: 2.2
9
+ gemfile: gemfiles/Gemfile.activesupport4
10
+ - rvm: 2.1
11
+ gemfile: gemfiles/Gemfile.activesupport4
12
+ - rvm: 2.0
13
+ gemfile: gemfiles/Gemfile.activesupport4
14
+ - rvm: jruby-9.1.5.0
15
+ jdk: oraclejdk8
16
+ gemfile: gemfiles/Gemfile.activesupport5
17
+ env:
18
+ - JRUBY_OPTS='--debug'
11
19
 
12
20
  services:
13
21
  - rabbitmq
14
-
15
- matrix:
16
- allow_failures:
17
- - rvm: jruby-9.0.0.0
data/CHANGELOG.md CHANGED
@@ -1,9 +1,26 @@
1
1
  ## 0.23.0 — (unreleased)
2
2
 
3
- No changes yet.
3
+ This release contains a **breaking change** in the error
4
+ handlers interface.
4
5
 
6
+ ### All Message Properties Passed to Error Handlers
5
7
 
6
- ## 0.22.0 June 7th, 2016
8
+ Previously error handlers were provided a message ID as first
9
+ argument to `ErrorHandler#handle`. Now it is a hash of all message
10
+ properties.
11
+
12
+ This is a **breaking public API change**. If you do not use custom
13
+ error handlers, you are not affected.
14
+
15
+ Contributed by Pierre-Louis Gottfrois.
16
+
17
+ GH issue: [hutch#238](https://github.com/gocardless/hutch/pull/238)
18
+
19
+ ### Opbeat Error Handler
20
+
21
+ Contributed by Olle Jonsson.
22
+
23
+ ## 0.22.1 — June 7th, 2016
7
24
 
8
25
  ### Message Payload is Reported to Sentry
9
26
 
data/Gemfile CHANGED
@@ -4,16 +4,25 @@ gemspec
4
4
 
5
5
  group :development do
6
6
  gem "rake"
7
- gem "guard", "~> 0.8.8"
8
- gem "guard-rspec", "~> 0.5.4"
7
+ gem "guard", "~> 2.14", platform: :mri_23
8
+ gem "guard-rspec", "~> 4.7", platform: :mri_23
9
+
10
+ gem "yard", "~> 0.9"
11
+ gem 'kramdown', "> 0", platform: :jruby
12
+ gem "redcarpet", "> 0", platform: :mri
13
+ gem "github-markup", "> 0"
9
14
  end
10
15
 
11
16
  group :development, :test do
17
+ gem "rspec", "~> 3.0"
18
+ gem "simplecov", "~> 0.12"
19
+
12
20
  gem "sentry-raven"
13
21
  gem "honeybadger"
14
- gem "coveralls", require: false
22
+ gem "coveralls", "~> 0.8.15", require: false
15
23
  gem "newrelic_rpm"
16
- gem "airbrake", "~> 4.0"
24
+ gem "airbrake", "~> 5.0"
25
+ gem "opbeat", "~> 3.0.9"
17
26
  end
18
27
 
19
28
  group :development, :darwin do
data/Guardfile CHANGED
@@ -1,5 +1,14 @@
1
- guard 'rspec', :version => 2, :cli => '--color --format doc' do
2
- watch(%r{^spec/.+_spec\.rb$})
3
- watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
4
- watch('spec/spec_helper.rb') { "spec" }
1
+ guard :rspec, cmd: "bundle exec rspec" do
2
+ require "guard/rspec/dsl"
3
+ dsl = Guard::RSpec::Dsl.new(self)
4
+
5
+ # RSpec files
6
+ rspec = dsl.rspec
7
+ watch(rspec.spec_helper) { rspec.spec_dir }
8
+ watch(rspec.spec_support) { rspec.spec_dir }
9
+ watch(rspec.spec_files)
10
+
11
+ # Ruby files
12
+ ruby = dsl.ruby
13
+ dsl.watch_spec_files_for(ruby.lib_files)
5
14
  end
data/README.md CHANGED
@@ -3,10 +3,10 @@
3
3
  Hutch is a Ruby library for enabling asynchronous inter-service communication
4
4
  in a service-oriented architecture, using RabbitMQ.
5
5
 
6
- [![Gem Version](https://badge.fury.io/rb/hutch.png)](http://badge.fury.io/rb/hutch)
7
- [![Build Status](https://travis-ci.org/gocardless/hutch.png?branch=master)](https://travis-ci.org/gocardless/hutch)
8
- [![Dependency Status](https://gemnasium.com/gocardless/hutch.png)](https://gemnasium.com/gocardless/hutch)
9
- [![Code Climate](https://codeclimate.com/github/gocardless/hutch.png)](https://codeclimate.com/github/gocardless/hutch)
6
+ [![Gem Version](https://badge.fury.io/rb/hutch.svg)](http://badge.fury.io/rb/hutch)
7
+ [![Build Status](https://travis-ci.org/gocardless/hutch.svg?branch=master)](https://travis-ci.org/gocardless/hutch)
8
+ [![Dependency Status](https://gemnasium.com/gocardless/hutch.svg)](https://gemnasium.com/gocardless/hutch)
9
+ [![Code Climate](https://codeclimate.com/github/gocardless/hutch.svg)](https://codeclimate.com/github/gocardless/hutch)
10
10
 
11
11
  To install with RubyGems:
12
12
 
@@ -317,6 +317,20 @@ Known configuration parameters are:
317
317
  * `write_timeout`: Bunny's socket write timeout (default: `11`)
318
318
  * `tracer`: tracer to use to track message processing
319
319
 
320
+ ### Environment variables
321
+
322
+ The file configuration options mentioned above can also be passed in via environment variables, using the `HUTCH_` prefix, eg.
323
+
324
+ * `connection_timeout` → `HUTCH_CONNECTION_TIMEOUT`.
325
+
326
+ ### Configuration precedence
327
+
328
+ In order from lowest to highest precedence:
329
+
330
+ 0. Default values
331
+ 0. `HUTCH_*` environment variables
332
+ 0. Configuration file
333
+ 0. Explicit settings through `Hutch::Config.set`
320
334
 
321
335
  ## Supported RabbitMQ Versions
322
336
 
@@ -0,0 +1,2 @@
1
+ eval_gemfile File.expand_path('../../Gemfile', __FILE__)
2
+ gem 'activesupport', '~> 4.0'
@@ -0,0 +1,2 @@
1
+ eval_gemfile File.expand_path('../../Gemfile', __FILE__)
2
+ gem 'activesupport', '>= 4.0'
data/hutch.gemspec CHANGED
@@ -6,22 +6,18 @@ Gem::Specification.new do |gem|
6
6
  gem.add_runtime_dependency 'march_hare', '>= 2.16.0'
7
7
  else
8
8
  gem.platform = Gem::Platform::RUBY
9
- gem.add_runtime_dependency 'bunny', '>= 2.3.1'
9
+ gem.add_runtime_dependency 'bunny', '>= 2.6.0'
10
10
  end
11
11
  gem.add_runtime_dependency 'carrot-top', '~> 0.0.7'
12
- gem.add_runtime_dependency 'multi_json', '~> 1.11.2'
13
- gem.add_runtime_dependency 'activesupport', '>= 3.0'
14
- gem.add_development_dependency 'rspec', '~> 3.0'
15
- gem.add_development_dependency 'simplecov', '~> 0.7.1'
16
- gem.add_development_dependency 'yard', '~> 0.8'
17
- gem.add_development_dependency 'redcarpet', '> 0'
18
- gem.add_development_dependency 'github-markup', '> 0'
12
+ gem.add_runtime_dependency 'multi_json', '~> 1.12'
13
+ gem.add_runtime_dependency 'activesupport'
19
14
 
20
15
  gem.name = 'hutch'
21
16
  gem.summary = 'Easy inter-service communication using RabbitMQ.'
22
17
  gem.description = 'Hutch is a Ruby library for enabling asynchronous ' +
23
18
  'inter-service communication using RabbitMQ.'
24
19
  gem.version = Hutch::VERSION.dup
20
+ gem.required_ruby_version = '>= 2.0'
25
21
  gem.authors = ['Harry Marr']
26
22
  gem.email = ['developers@gocardless.com']
27
23
  gem.homepage = 'https://github.com/gocardless/hutch'
data/lib/hutch/broker.rb CHANGED
@@ -245,6 +245,7 @@ module Hutch
245
245
  end
246
246
 
247
247
  private
248
+
248
249
  def api_config
249
250
  @api_config ||= OpenStruct.new.tap do |config|
250
251
  config.host = @config[:mq_api_host]
data/lib/hutch/config.rb CHANGED
@@ -134,9 +134,12 @@ module Hutch
134
134
  ALL_KEYS = @boolean_keys + @number_keys + @string_keys
135
135
 
136
136
  def self.initialize(params = {})
137
- @config = default_config
138
- @config.merge!(env_based_config).merge!(params)
139
- define_methods
137
+ unless @config
138
+ @config = default_config
139
+ define_methods
140
+ @config.merge!(env_based_config)
141
+ end
142
+ @config.merge!(params)
140
143
  @config
141
144
  end
142
145
 
@@ -191,8 +194,8 @@ module Hutch
191
194
  end
192
195
 
193
196
  def self.get(attr)
194
- check_attr(attr)
195
- user_config[attr]
197
+ check_attr(attr.to_sym)
198
+ user_config[attr.to_sym]
196
199
  end
197
200
 
198
201
  def self.key_for(attr)
@@ -213,8 +216,8 @@ module Hutch
213
216
  end
214
217
 
215
218
  def self.set(attr, value)
216
- check_attr(attr)
217
- user_config[attr] = value
219
+ check_attr(attr.to_sym)
220
+ user_config[attr.to_sym] = value
218
221
  end
219
222
 
220
223
  class << self
@@ -264,3 +267,4 @@ module Hutch
264
267
  end
265
268
  end
266
269
  end
270
+ Hutch::Config.initialize
@@ -4,5 +4,6 @@ module Hutch
4
4
  autoload :Sentry, 'hutch/error_handlers/sentry'
5
5
  autoload :Honeybadger, 'hutch/error_handlers/honeybadger'
6
6
  autoload :Airbrake, 'hutch/error_handlers/airbrake'
7
+ autoload :Opbeat, 'hutch/error_handlers/opbeat'
7
8
  end
8
9
  end
@@ -6,20 +6,30 @@ module Hutch
6
6
  class Airbrake
7
7
  include Logging
8
8
 
9
- def handle(message_id, payload, consumer, ex)
9
+ def handle(properties, payload, consumer, ex)
10
+ message_id = properties.message_id
10
11
  prefix = "message(#{message_id || '-'}): "
11
12
  logger.error prefix + "Logging event to Airbrake"
12
13
  logger.error prefix + "#{ex.class} - #{ex.message}"
13
- ::Airbrake.notify_or_ignore(ex, {
14
- :error_class => ex.class.name,
15
- :error_message => "#{ ex.class.name }: #{ ex.message }",
16
- :backtrace => ex.backtrace,
17
- :parameters => {
18
- :payload => payload,
19
- :consumer => consumer,
20
- },
21
- :cgi_data => ENV.to_hash,
22
- })
14
+
15
+ if ::Airbrake.respond_to?(:notify_or_ignore)
16
+ ::Airbrake.notify_or_ignore(ex, {
17
+ error_class: ex.class.name,
18
+ error_message: "#{ ex.class.name }: #{ ex.message }",
19
+ backtrace: ex.backtrace,
20
+ parameters: {
21
+ payload: payload,
22
+ consumer: consumer,
23
+ },
24
+ cgi_data: ENV.to_hash,
25
+ })
26
+ else
27
+ ::Airbrake.notify(ex, {
28
+ payload: payload,
29
+ consumer: consumer,
30
+ cgi_data: ENV.to_hash,
31
+ })
32
+ end
23
33
  end
24
34
  end
25
35
  end
@@ -6,7 +6,8 @@ module Hutch
6
6
  class Honeybadger
7
7
  include Logging
8
8
 
9
- def handle(message_id, payload, consumer, ex)
9
+ def handle(properties, payload, consumer, ex)
10
+ message_id = properties.message_id
10
11
  prefix = "message(#{message_id || '-'}): "
11
12
  logger.error prefix + "Logging event to Honeybadger"
12
13
  logger.error prefix + "#{ex.class} - #{ex.message}"
@@ -5,7 +5,8 @@ module Hutch
5
5
  class Logger
6
6
  include Logging
7
7
 
8
- def handle(message_id, payload, consumer, ex)
8
+ def handle(properties, payload, consumer, ex)
9
+ message_id = properties.message_id
9
10
  prefix = "message(#{message_id || '-'}): "
10
11
  logger.error prefix + "error in consumer '#{consumer}'"
11
12
  logger.error prefix + "#{ex.class} - #{ex.message}"
@@ -0,0 +1,24 @@
1
+ require 'hutch/logging'
2
+ require 'opbeat'
3
+
4
+ module Hutch
5
+ module ErrorHandlers
6
+ class Opbeat
7
+ include Logging
8
+
9
+ def initialize
10
+ unless ::Opbeat.respond_to?(:report)
11
+ raise "The Opbeat error handler requires Opbeat >= 3.0"
12
+ end
13
+ end
14
+
15
+ def handle(properties, payload, consumer, ex)
16
+ message_id = properties.message_id
17
+ prefix = "message(#{message_id || '-'}):"
18
+ logger.error "#{prefix} Logging event to Opbeat"
19
+ logger.error "#{prefix} #{ex.class} - #{ex.message}"
20
+ ::Opbeat.report(ex, extra: { payload: payload })
21
+ end
22
+ end
23
+ end
24
+ end
@@ -12,7 +12,8 @@ module Hutch
12
12
  end
13
13
  end
14
14
 
15
- def handle(message_id, payload, consumer, ex)
15
+ def handle(properties, payload, consumer, ex)
16
+ message_id = properties.message_id
16
17
  prefix = "message(#{message_id || '-'}): "
17
18
  logger.error prefix + "Logging event to Sentry"
18
19
  logger.error prefix + "#{ex.class} - #{ex.message}"
data/lib/hutch/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Hutch
2
- VERSION = '0.22.1'.freeze
2
+ VERSION = '0.23.0'.freeze
3
3
  end
4
4
 
data/lib/hutch/waiter.rb CHANGED
@@ -4,7 +4,7 @@ module Hutch
4
4
  class Waiter
5
5
  include Logging
6
6
 
7
- SHUTDOWN_SIGNALS = %w(QUIT TERM INT)
7
+ SHUTDOWN_SIGNALS = %w(QUIT TERM INT).keep_if { |s| Signal.list.keys.include? s }.freeze
8
8
 
9
9
  def self.wait_until_signaled
10
10
  new.wait_until_signaled
data/lib/hutch/worker.rb CHANGED
@@ -9,8 +9,6 @@ module Hutch
9
9
  class Worker
10
10
  include Logging
11
11
 
12
- SHUTDOWN_SIGNALS = %w(QUIT TERM INT)
13
-
14
12
  def initialize(broker, consumers, setup_procs)
15
13
  @broker = broker
16
14
  self.consumers = consumers
@@ -70,16 +68,16 @@ module Hutch
70
68
  @broker.ack(delivery_info.delivery_tag)
71
69
  rescue => ex
72
70
  acknowledge_error(delivery_info, properties, @broker, ex)
73
- handle_error(properties.message_id, payload, consumer, ex)
71
+ handle_error(properties, payload, consumer, ex)
74
72
  end
75
73
 
76
74
  def with_tracing(klass)
77
75
  Hutch::Config[:tracer].new(klass)
78
76
  end
79
77
 
80
- def handle_error(message_id, payload, consumer, ex)
78
+ def handle_error(*args)
81
79
  Hutch::Config[:error_handlers].each do |backend|
82
- backend.handle(message_id, payload, consumer, ex)
80
+ backend.handle(*args)
83
81
  end
84
82
  end
85
83
 
@@ -2,8 +2,16 @@ require 'spec_helper'
2
2
  require 'hutch/broker'
3
3
 
4
4
  describe Hutch::Broker do
5
- let(:config) { Hutch::Config.initialize(client_logger: Hutch::Logging.logger) }
6
- subject(:broker) { Hutch::Broker.new(config) }
5
+ before do
6
+ Hutch::Config.initialize(client_logger: Hutch::Logging.logger)
7
+ @config = Hutch::Config.to_hash
8
+ end
9
+ let!(:config) { @config }
10
+ after do
11
+ Hutch::Config.instance_variable_set(:@config, nil)
12
+ Hutch::Config.initialize
13
+ end
14
+ let(:broker) { Hutch::Broker.new(config) }
7
15
 
8
16
  describe '#connect' do
9
17
  before { allow(broker).to receive(:set_up_amqp_connection) }
@@ -195,7 +203,7 @@ describe Hutch::Broker do
195
203
  after { broker.disconnect }
196
204
 
197
205
  describe '#api_client' do
198
- subject { super().api_client }
206
+ subject { broker.api_client }
199
207
  it { is_expected.to be_a CarrotTop }
200
208
  end
201
209
  end
@@ -321,12 +329,12 @@ describe Hutch::Broker do
321
329
 
322
330
  it 'publishes to the exchange' do
323
331
  expect(broker.exchange).to receive(:publish).once
324
- broker.publish('test.key', 'message')
332
+ broker.publish('test.key', {key: "value"})
325
333
  end
326
334
 
327
335
  it 'sets default properties' do
328
336
  expect(broker.exchange).to receive(:publish).with(
329
- JSON.dump("message"),
337
+ JSON.dump({key: "value"}),
330
338
  hash_including(
331
339
  persistent: true,
332
340
  routing_key: 'test.key',
@@ -334,12 +342,12 @@ describe Hutch::Broker do
334
342
  )
335
343
  )
336
344
 
337
- broker.publish('test.key', 'message')
345
+ broker.publish('test.key', {key: "value"})
338
346
  end
339
347
 
340
348
  it 'allows passing message properties' do
341
349
  expect(broker.exchange).to receive(:publish).once
342
- broker.publish('test.key', 'message', {expiration: "2000", persistent: false})
350
+ broker.publish('test.key', {key: "value"}, {expiration: "2000", persistent: false})
343
351
  end
344
352
 
345
353
  context 'when there are global properties' do
@@ -350,8 +358,8 @@ describe Hutch::Broker do
350
358
 
351
359
  it 'merges the properties' do
352
360
  expect(broker.exchange).
353
- to receive(:publish).with('"message"', hash_including(app_id: 'app'))
354
- broker.publish('test.key', 'message')
361
+ to receive(:publish).with('{"key":"value"}', hash_including(app_id: 'app'))
362
+ broker.publish('test.key', {key: "value"})
355
363
  end
356
364
  end
357
365
 
@@ -362,8 +370,8 @@ describe Hutch::Broker do
362
370
 
363
371
  it 'calls the proc and merges the properties' do
364
372
  expect(broker.exchange).
365
- to receive(:publish).with('"message"', hash_including(app_id: 'app'))
366
- broker.publish('test.key', 'message')
373
+ to receive(:publish).with('{"key":"value"}', hash_including(app_id: 'app'))
374
+ broker.publish('test.key', {key: "value"})
367
375
  end
368
376
  end
369
377
  end
@@ -372,13 +380,13 @@ describe Hutch::Broker do
372
380
  it 'does not wait for confirms on the channel', adapter: :bunny do
373
381
  expect_any_instance_of(Bunny::Channel).
374
382
  to_not receive(:wait_for_confirms)
375
- broker.publish('test.key', 'message')
383
+ broker.publish('test.key', {key: "value"})
376
384
  end
377
385
 
378
386
  it 'does not wait for confirms on the channel', adapter: :march_hare do
379
387
  expect_any_instance_of(MarchHare::Channel).
380
388
  to_not receive(:wait_for_confirms)
381
- broker.publish('test.key', 'message')
389
+ broker.publish('test.key', {key: "value"})
382
390
  end
383
391
  end
384
392
 
@@ -392,13 +400,13 @@ describe Hutch::Broker do
392
400
  it 'waits for confirms on the channel', adapter: :bunny do
393
401
  expect_any_instance_of(Bunny::Channel).
394
402
  to receive(:wait_for_confirms)
395
- broker.publish('test.key', 'message')
403
+ broker.publish('test.key', {key: "value"})
396
404
  end
397
405
 
398
406
  it 'waits for confirms on the channel', adapter: :march_hare do
399
407
  expect_any_instance_of(MarchHare::Channel).
400
408
  to receive(:wait_for_confirms)
401
- broker.publish('test.key', 'message')
409
+ broker.publish('test.key', {key: "value"})
402
410
  end
403
411
  end
404
412
  end
@@ -407,13 +415,13 @@ describe Hutch::Broker do
407
415
  before { broker.set_up_amqp_connection; broker.disconnect }
408
416
 
409
417
  it 'raises an exception' do
410
- expect { broker.publish('test.key', 'message') }.
418
+ expect { broker.publish('test.key', {key: "value"}) }.
411
419
  to raise_exception(Hutch::PublishError)
412
420
  end
413
421
 
414
422
  it 'logs an error' do
415
423
  expect(broker.logger).to receive(:error)
416
- broker.publish('test.key', 'message') rescue nil
424
+ broker.publish('test.key', {key: "value"}) rescue nil
417
425
  end
418
426
  end
419
427
  end
@@ -5,9 +5,14 @@ describe Hutch::Config do
5
5
  let(:new_value) { 'not-localhost' }
6
6
 
7
7
  before do
8
+ Hutch::Config.instance_variable_set(:@config, nil)
8
9
  Hutch::Config.initialize
9
10
  end
10
11
 
12
+ after do
13
+ Hutch::Config.instance_variable_set(:@config, nil)
14
+ end
15
+
11
16
  describe '.get' do
12
17
  context 'for valid attributes' do
13
18
  subject { Hutch::Config.get(:mq_host) }
@@ -18,9 +23,7 @@ describe Hutch::Config do
18
23
 
19
24
  context 'with an overridden value' do
20
25
  before do
21
- allow(Hutch::Config).to receive_messages(
22
- user_config: { mq_host: new_value }
23
- )
26
+ Hutch::Config.set(:mq_host, new_value)
24
27
  end
25
28
 
26
29
  it { is_expected.to eq(new_value) }
@@ -161,4 +164,24 @@ YAML
161
164
  end
162
165
  end
163
166
  end
167
+
168
+ context 'developer ergonomics' do
169
+ it 'will accept strings and symbols as config keys' do
170
+ expect(Hutch::Config.get(:mq_host)).to eq '127.0.0.1'
171
+ expect(Hutch::Config.get('mq_host')).to eq '127.0.0.1'
172
+ end
173
+
174
+ describe 'it will not overwrite existing config' do
175
+ it 'with defaults' do
176
+ expect(Hutch::Config.get(:mq_host)).to eq '127.0.0.1'
177
+ Hutch::Config.initialize
178
+
179
+ Hutch::Config.set(:mq_host, 'example2.com')
180
+
181
+ expect(Hutch::Config.get(:mq_host)).to eq 'example2.com'
182
+ Hutch::Config.initialize
183
+ expect(Hutch::Config.get(:mq_host)).to eq 'example2.com'
184
+ end
185
+ end
186
+ end
164
187
  end
@@ -14,21 +14,17 @@ describe Hutch::ErrorHandlers::Airbrake do
14
14
 
15
15
  it "logs the error to Airbrake" do
16
16
  message_id = "1"
17
+ properties = OpenStruct.new(message_id: message_id)
17
18
  payload = "{}"
18
19
  consumer = double
19
20
  ex = error
20
21
  message = {
21
- :error_class => ex.class.name,
22
- :error_message => "#{ ex.class.name }: #{ ex.message }",
23
- :backtrace => ex.backtrace,
24
- :parameters => {
25
- :payload => payload,
26
- :consumer => consumer,
27
- },
28
- :cgi_data => ENV.to_hash,
22
+ payload: payload,
23
+ consumer: consumer,
24
+ cgi_data: ENV.to_hash,
29
25
  }
30
- expect(::Airbrake).to receive(:notify_or_ignore).with(ex, message)
31
- error_handler.handle(message_id, payload, consumer, ex)
26
+ expect(::Airbrake).to receive(:notify).with(ex, message)
27
+ error_handler.handle(properties, payload, consumer, ex)
32
28
  end
33
29
  end
34
30
  end
@@ -14,6 +14,7 @@ describe Hutch::ErrorHandlers::Honeybadger do
14
14
 
15
15
  it "logs the error to Honeybadger" do
16
16
  message_id = "1"
17
+ properties = OpenStruct.new(message_id: message_id)
17
18
  payload = "{}"
18
19
  consumer = double
19
20
  ex = error
@@ -30,7 +31,7 @@ describe Hutch::ErrorHandlers::Honeybadger do
30
31
  }
31
32
  }
32
33
  expect(::Honeybadger).to receive(:notify_or_ignore).with(message)
33
- error_handler.handle(message_id, payload, consumer, ex)
34
+ error_handler.handle(properties, payload, consumer, ex)
34
35
  end
35
36
  end
36
37
  end
@@ -4,12 +4,14 @@ describe Hutch::ErrorHandlers::Logger do
4
4
  let(:error_handler) { Hutch::ErrorHandlers::Logger.new }
5
5
 
6
6
  describe '#handle' do
7
+ let(:properties) { OpenStruct.new(message_id: "1") }
8
+ let(:payload) { "{}" }
7
9
  let(:error) { double(message: "Stuff went wrong", class: "RuntimeError",
8
10
  backtrace: ["line 1", "line 2"]) }
9
11
 
10
12
  it "logs three separate lines" do
11
13
  expect(Hutch::Logging.logger).to receive(:error).exactly(3).times
12
- error_handler.handle("1", "{}", double, error)
14
+ error_handler.handle(properties, payload, double, error)
13
15
  end
14
16
  end
15
17
  end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hutch::ErrorHandlers::Opbeat do
4
+ let(:error_handler) { Hutch::ErrorHandlers::Opbeat.new }
5
+
6
+ describe '#handle' do
7
+ let(:properties) { OpenStruct.new(message_id: "1") }
8
+ let(:payload) { "{}" }
9
+ let(:error) do
10
+ begin
11
+ raise "Stuff went wrong"
12
+ rescue RuntimeError => err
13
+ err
14
+ end
15
+ end
16
+
17
+ it "logs the error to Opbeat" do
18
+ expect(Opbeat).to receive(:report).with(error, extra: { payload: payload })
19
+ error_handler.handle(properties, payload, double, error)
20
+ end
21
+ end
22
+ end
@@ -4,6 +4,8 @@ describe Hutch::ErrorHandlers::Sentry do
4
4
  let(:error_handler) { Hutch::ErrorHandlers::Sentry.new }
5
5
 
6
6
  describe '#handle' do
7
+ let(:properties) { OpenStruct.new(message_id: "1") }
8
+ let(:payload) { "{}" }
7
9
  let(:error) do
8
10
  begin
9
11
  raise "Stuff went wrong"
@@ -13,8 +15,8 @@ describe Hutch::ErrorHandlers::Sentry do
13
15
  end
14
16
 
15
17
  it "logs the error to Sentry" do
16
- expect(Raven).to receive(:capture_exception).with(error, extra: { payload: "{}" })
17
- error_handler.handle("1", "{}", double, error)
18
+ expect(Raven).to receive(:capture_exception).with(error, extra: { payload: payload })
19
+ error_handler.handle(properties, payload, double, error)
18
20
  end
19
21
  end
20
22
  end
@@ -12,7 +12,11 @@ RSpec.describe Hutch::Waiter do
12
12
  end
13
13
  end
14
14
 
15
- %w(QUIT TERM INT).each do |signal|
15
+ described_class::SHUTDOWN_SIGNALS.each do |signal|
16
+ # JRuby does not support QUIT:
17
+ # The signal QUIT is in use by the JVM and will not work correctly on this platform
18
+ next if signal == 'QUIT' && defined?(JRUBY_VERSION)
19
+
16
20
  context "a #{signal} signal is received" do
17
21
  it "logs that hutch is stopping" do
18
22
  expect(Hutch::Logging.logger).to receive(:info)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hutch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.22.1
4
+ version: 0.23.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Harry Marr
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-06 00:00:00.000000000 Z
11
+ date: 2016-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bunny
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 2.3.1
19
+ version: 2.6.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 2.3.1
26
+ version: 2.6.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: carrot-top
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,96 +44,26 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 1.11.2
47
+ version: '1.12'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 1.11.2
54
+ version: '1.12'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: activesupport
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '3.0'
61
+ version: '0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '3.0'
69
- - !ruby/object:Gem::Dependency
70
- name: rspec
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '3.0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '3.0'
83
- - !ruby/object:Gem::Dependency
84
- name: simplecov
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: 0.7.1
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: 0.7.1
97
- - !ruby/object:Gem::Dependency
98
- name: yard
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: '0.8'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - "~>"
109
- - !ruby/object:Gem::Version
110
- version: '0.8'
111
- - !ruby/object:Gem::Dependency
112
- name: redcarpet
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ">"
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ">"
123
- - !ruby/object:Gem::Version
124
- version: '0'
125
- - !ruby/object:Gem::Dependency
126
- name: github-markup
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - ">"
130
- - !ruby/object:Gem::Version
131
- version: '0'
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - ">"
137
67
  - !ruby/object:Gem::Version
138
68
  version: '0'
139
69
  description: Hutch is a Ruby library for enabling asynchronous inter-service communication
@@ -146,6 +76,7 @@ extensions: []
146
76
  extra_rdoc_files: []
147
77
  files:
148
78
  - ".gitignore"
79
+ - ".rspec"
149
80
  - ".travis.yml"
150
81
  - ".yardopts"
151
82
  - CHANGELOG.md
@@ -157,6 +88,8 @@ files:
157
88
  - bin/hutch
158
89
  - examples/consumer.rb
159
90
  - examples/producer.rb
91
+ - gemfiles/Gemfile.activesupport4
92
+ - gemfiles/Gemfile.activesupport5
160
93
  - hutch.gemspec
161
94
  - lib/hutch.rb
162
95
  - lib/hutch/acknowledgements/base.rb
@@ -172,6 +105,7 @@ files:
172
105
  - lib/hutch/error_handlers/airbrake.rb
173
106
  - lib/hutch/error_handlers/honeybadger.rb
174
107
  - lib/hutch/error_handlers/logger.rb
108
+ - lib/hutch/error_handlers/opbeat.rb
175
109
  - lib/hutch/error_handlers/sentry.rb
176
110
  - lib/hutch/exceptions.rb
177
111
  - lib/hutch/logging.rb
@@ -194,6 +128,7 @@ files:
194
128
  - spec/hutch/error_handlers/airbrake_spec.rb
195
129
  - spec/hutch/error_handlers/honeybadger_spec.rb
196
130
  - spec/hutch/error_handlers/logger_spec.rb
131
+ - spec/hutch/error_handlers/opbeat_spec.rb
197
132
  - spec/hutch/error_handlers/sentry_spec.rb
198
133
  - spec/hutch/logger_spec.rb
199
134
  - spec/hutch/message_spec.rb
@@ -223,7 +158,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
223
158
  requirements:
224
159
  - - ">="
225
160
  - !ruby/object:Gem::Version
226
- version: '0'
161
+ version: '2.0'
227
162
  required_rubygems_version: !ruby/object:Gem::Requirement
228
163
  requirements:
229
164
  - - ">="
@@ -231,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
231
166
  version: '0'
232
167
  requirements: []
233
168
  rubyforge_project:
234
- rubygems_version: 2.5.1
169
+ rubygems_version: 2.4.8
235
170
  signing_key:
236
171
  specification_version: 4
237
172
  summary: Easy inter-service communication using RabbitMQ.
@@ -243,6 +178,7 @@ test_files:
243
178
  - spec/hutch/error_handlers/airbrake_spec.rb
244
179
  - spec/hutch/error_handlers/honeybadger_spec.rb
245
180
  - spec/hutch/error_handlers/logger_spec.rb
181
+ - spec/hutch/error_handlers/opbeat_spec.rb
246
182
  - spec/hutch/error_handlers/sentry_spec.rb
247
183
  - spec/hutch/logger_spec.rb
248
184
  - spec/hutch/message_spec.rb
@@ -251,4 +187,3 @@ test_files:
251
187
  - spec/hutch/worker_spec.rb
252
188
  - spec/hutch_spec.rb
253
189
  - spec/spec_helper.rb
254
- has_rdoc: