hutch 1.1.1 → 1.2.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
  SHA256:
3
- metadata.gz: 9725ddb3e39e305bad95abd6c8605c1d9828691904bb2ae31430fd22d88bd180
4
- data.tar.gz: db1d87d81de0f89c84b1ec387c66443aa9ead6be2d71b50b6cee32e9146dd080
3
+ metadata.gz: 9c376d628987a9352a8ff9e49cd48ae0c12364cc3f9393185e8c811ff3052213
4
+ data.tar.gz: 3aa07c8285817c1fefa10b7dc2b65e3fccf0b62ffbaf7a89e4b09f9a6db67035
5
5
  SHA512:
6
- metadata.gz: 296138c5cb4c08340f4a72bb8d30009402272f9843efffd0dc1d647328ca1531d188fd3b5a9a15f891f4a8447dbf5f72a7a583aa702f1c999fc557c1ab4ac024
7
- data.tar.gz: 2c0406261d2535d5e5d00037e20e29f5cb781e337732491cf36195231e5d647b75c0d96d74c0861afa36cfb24575a0e2b34ce06f59693a98b84342cf1d52ad95
6
+ metadata.gz: 0c0ba8155050290ebe63628ce10f9fdbd93e4ec483ce8e465564f9635913082d662f2b9f05ca3227f5ad6f5d9c773e9e9653abfbc867f816db0ddf589093d388
7
+ data.tar.gz: 2ef54abbde9959378b15d1e60062b62ae0b55e8299029fa4fade407f6f9006b6df327f547dc2ba771638fa8d1e512860f0a78f4dc1fe145b337afb4d4000ea64
@@ -1,10 +1,13 @@
1
1
  name: Test
2
2
 
3
+ concurrency:
4
+ group: ${{ github.ref }}
5
+ cancel-in-progress: true
6
+
3
7
  on:
4
8
  push:
5
9
  branches: [ master ]
6
10
  pull_request:
7
- branches: [ master ]
8
11
 
9
12
  jobs:
10
13
  test:
@@ -22,10 +25,13 @@ jobs:
22
25
  strategy:
23
26
  fail-fast: false
24
27
  matrix:
25
- ruby-version: ['jruby-9.2.19.0', 'jruby-9.3.0.0', 'jruby-head']
28
+ ruby-version:
29
+ - 2.7
30
+ - 3.0
31
+ - 3.1
26
32
 
27
33
  steps:
28
- - uses: actions/checkout@v2
34
+ - uses: actions/checkout@v3
29
35
  - name: Set up Ruby
30
36
  # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
31
37
  # change this to (see https://github.com/ruby/setup-ruby#versioning):
@@ -40,3 +46,12 @@ jobs:
40
46
  ./bin/ci/before_build_docker.sh
41
47
  - name: Run tests
42
48
  run: bundle exec rspec spec
49
+ test_all:
50
+ if: ${{ always() }}
51
+ runs-on: ubuntu-latest
52
+ name: Test (matrix)
53
+ needs: test
54
+ steps:
55
+ - name: Check test matrix status
56
+ if: ${{ needs.test.result != 'success' }}
57
+ run: exit 1
data/Gemfile CHANGED
@@ -24,7 +24,7 @@ group :development, :test do
24
24
  gem "honeybadger"
25
25
  gem "coveralls", "~> 0.8.15", require: false
26
26
  gem "newrelic_rpm"
27
- gem "ddtrace"
27
+ gem "ddtrace", "~> 0.54.2"
28
28
  gem "airbrake", "~> 10.0"
29
29
  gem "rollbar"
30
30
  gem "bugsnag"
File without changes
data/lib/hutch/broker.rb CHANGED
@@ -174,8 +174,8 @@ module Hutch
174
174
  def queue(name, options = {})
175
175
  with_bunny_precondition_handler('queue') do
176
176
  namespace = @config[:namespace].to_s.downcase.gsub(/[^-_:\.\w]/, "")
177
- name = name.prepend(namespace + ":") if namespace.present?
178
- channel.queue(name, **options)
177
+ queue_name = namespace.present? ? "#{namespace}:#{name}" : name
178
+ channel.queue(queue_name, **options)
179
179
  end
180
180
  end
181
181
 
@@ -287,6 +287,7 @@ module Hutch
287
287
  params[:host] = @config[:mq_host]
288
288
  params[:port] = @config[:mq_port]
289
289
  params[:vhost] = @config[:mq_vhost].presence || Hutch::Adapter::DEFAULT_VHOST
290
+ params[:auth_mechanism] = @config[:mq_auth_mechanism]
290
291
  params[:username] = @config[:mq_username]
291
292
  params[:password] = @config[:mq_password]
292
293
  params[:tls] = @config[:mq_tls]
data/lib/hutch/cli.rb CHANGED
@@ -65,7 +65,7 @@ module Hutch
65
65
  return false
66
66
  ensure
67
67
  # Clean up load path
68
- $LOAD_PATH.pop
68
+ $LOAD_PATH.delete('.')
69
69
  end
70
70
  end
71
71
  end
data/lib/hutch/config.rb CHANGED
@@ -63,6 +63,9 @@ module Hutch
63
63
  # RabbitMQ password
64
64
  string_setting :mq_password, 'guest'
65
65
 
66
+ # RabbitMQ Auth Mechanism
67
+ string_setting :mq_auth_mechanism, 'PLAIN'
68
+
66
69
  # RabbitMQ URI (takes precedence over MQ username, password, host, port and vhost settings)
67
70
  string_setting :uri, nil
68
71
 
@@ -222,7 +225,12 @@ module Hutch
222
225
  end
223
226
 
224
227
  def self.to_bool(value)
225
- !(value.nil? || value == '' || value =~ /^(false|f|no|n|0)$/i || value == false)
228
+ case value
229
+ when nil, false, '', /^(false|f|no|n|0)$/i
230
+ false
231
+ else
232
+ true
233
+ end
226
234
  end
227
235
 
228
236
  def self.is_num(attr)
@@ -13,13 +13,19 @@ module Hutch
13
13
  end
14
14
 
15
15
  def reject!
16
+ @message_rejected = true
16
17
  broker.reject(delivery_info.delivery_tag)
17
18
  end
18
19
 
19
20
  def requeue!
21
+ @message_rejected = true
20
22
  broker.requeue(delivery_info.delivery_tag)
21
23
  end
22
24
 
25
+ def message_rejected?
26
+ !!@message_rejected
27
+ end
28
+
23
29
  def logger
24
30
  Hutch::Logging.logger
25
31
  end
@@ -11,7 +11,7 @@ module Hutch
11
11
  logger.error "#{prefix} Logging event to Sentry"
12
12
  logger.error "#{prefix} #{ex.class} - #{ex.message}"
13
13
  ::Sentry.configure_scope do |scope|
14
- scope.set_context("payload", payload)
14
+ scope.set_context("payload", JSON.parse(payload))
15
15
  end
16
16
  ::Sentry.capture_exception(ex)
17
17
  end
data/lib/hutch/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Hutch
2
- VERSION = '1.1.1'.freeze
2
+ VERSION = '1.2.0'.freeze
3
3
  end
data/lib/hutch/worker.rb CHANGED
@@ -71,7 +71,7 @@ module Hutch
71
71
  message = Message.new(delivery_info, properties, payload, serializer)
72
72
  consumer_instance = consumer.new.tap { |c| c.broker, c.delivery_info = @broker, delivery_info }
73
73
  with_tracing(consumer_instance).handle(message)
74
- @broker.ack(delivery_info.delivery_tag)
74
+ @broker.ack(delivery_info.delivery_tag) unless consumer_instance.message_rejected?
75
75
  rescue => ex
76
76
  acknowledge_error(delivery_info, properties, @broker, ex)
77
77
  handle_error(properties, payload, consumer, ex)
@@ -119,7 +119,7 @@ describe Hutch::Broker do
119
119
 
120
120
  it 'utilises TLS' do
121
121
  expect(Hutch::Adapter).to receive(:new).with(
122
- hash_including(tls: true, port: 5671)
122
+ hash_including(tls: true)
123
123
  ).and_return(instance_double('Hutch::Adapter', start: nil))
124
124
 
125
125
  broker.open_connection
@@ -245,9 +245,9 @@ describe Hutch::Broker do
245
245
  context 'when given invalid details' do
246
246
  before { config[:mq_api_host] = 'notarealhost' }
247
247
  after { broker.disconnect }
248
- let(:set_up_api_connection) { ->{ broker.set_up_api_connection } }
248
+ let(:set_up_api_connection) { broker.set_up_api_connection }
249
249
 
250
- specify { expect(set_up_api_connection).to raise_error(StandardError) }
250
+ specify { expect { broker.set_up_api_connection }.to raise_error(StandardError) }
251
251
  end
252
252
  end
253
253
 
@@ -262,7 +262,7 @@ describe Hutch::Broker do
262
262
  args.first == ''
263
263
  args.last == arguments
264
264
  end
265
- broker.queue('test', arguments: arguments)
265
+ broker.queue('test'.freeze, arguments: arguments)
266
266
  end
267
267
  end
268
268
 
@@ -31,12 +31,10 @@ describe Hutch::Config do
31
31
  end
32
32
 
33
33
  context 'for invalid attributes' do
34
- let(:invalid_get) do
35
- -> { Hutch::Config.get(:invalid_attr) }
36
- end
34
+ let(:invalid_get) { Hutch::Config.get(:invalid_attr) }
37
35
 
38
36
  specify do
39
- expect(invalid_get).to raise_error Hutch::UnknownAttributeError
37
+ expect { invalid_get }.to raise_error Hutch::UnknownAttributeError
40
38
  end
41
39
  end
42
40
  end
@@ -65,14 +63,52 @@ describe Hutch::Config do
65
63
  end
66
64
 
67
65
  context 'boolean attributes' do
68
- before { Hutch::Config.set(:autoload_rails, new_value) }
69
- subject(:value) { Hutch::Config.user_config[:autoload_rails] }
66
+ context 'from non-empty string' do
67
+ before { Hutch::Config.set(:autoload_rails, new_value) }
68
+ subject(:value) { Hutch::Config.user_config[:autoload_rails] }
70
69
 
71
- let(:new_value) { "t" }
70
+ let(:new_value) { "t" }
72
71
 
73
72
 
74
- specify 'casts values to booleans' do
75
- expect(value).to eq true
73
+ specify 'casts values to booleans' do
74
+ expect(value).to eq true
75
+ end
76
+ end
77
+
78
+ context 'from empty string' do
79
+ before { Hutch::Config.set(:autoload_rails, new_value) }
80
+ subject(:value) { Hutch::Config.user_config[:autoload_rails] }
81
+
82
+ let(:new_value) { "" }
83
+
84
+
85
+ specify 'casts values to booleans' do
86
+ expect(value).to eq false
87
+ end
88
+ end
89
+
90
+ context 'from boolean' do
91
+ before { Hutch::Config.set(:autoload_rails, new_value) }
92
+ subject(:value) { Hutch::Config.user_config[:autoload_rails] }
93
+
94
+ let(:new_value) { true }
95
+
96
+
97
+ specify 'casts values to booleans' do
98
+ expect(value).to eq true
99
+ end
100
+ end
101
+
102
+ context 'from nil' do
103
+ before { Hutch::Config.set(:autoload_rails, new_value) }
104
+ subject(:value) { Hutch::Config.user_config[:autoload_rails] }
105
+
106
+ let(:new_value) { nil }
107
+
108
+
109
+ specify 'casts values to booleans' do
110
+ expect(value).to eq false
111
+ end
76
112
  end
77
113
  end
78
114
 
@@ -90,12 +126,10 @@ describe Hutch::Config do
90
126
  end
91
127
 
92
128
  context 'for invalid attributes' do
93
- let(:invalid_set) do
94
- -> { Hutch::Config.set(:invalid_attr, new_value) }
95
- end
129
+ let(:invalid_set) { Hutch::Config.set(:invalid_attr, new_value) }
96
130
 
97
131
  specify do
98
- expect(invalid_set).to raise_error Hutch::UnknownAttributeError
132
+ expect { invalid_set }.to raise_error Hutch::UnknownAttributeError
99
133
  end
100
134
  end
101
135
  end
@@ -109,8 +143,8 @@ describe Hutch::Config do
109
143
  end
110
144
 
111
145
  context 'for an invalid attribute' do
112
- let(:invalid_getter) { -> { Hutch::Config.invalid_attr } }
113
- specify { expect(invalid_getter).to raise_error NoMethodError }
146
+ let(:invalid_getter) { Hutch::Config.invalid_attr }
147
+ specify { expect { invalid_getter }.to raise_error NoMethodError }
114
148
  end
115
149
 
116
150
  context 'for an ENV-overriden value attribute' do
@@ -147,8 +181,8 @@ describe Hutch::Config do
147
181
  end
148
182
 
149
183
  context 'for an invalid attribute' do
150
- let(:invalid_setter) { -> { Hutch::Config.invalid_attr = new_value } }
151
- specify { expect(invalid_setter).to raise_error NoMethodError }
184
+ let(:invalid_setter) { Hutch::Config.invalid_attr = new_value }
185
+ specify { expect { invalid_setter }.to raise_error NoMethodError }
152
186
  end
153
187
  end
154
188
 
@@ -3,6 +3,14 @@ require 'spec_helper'
3
3
  describe Hutch::ErrorHandlers::Sentry do
4
4
  let(:error_handler) { Hutch::ErrorHandlers::Sentry.new }
5
5
 
6
+ before do
7
+ Sentry.init do
8
+ # initialize Sentry so that the integration acutally works
9
+ # otherwise, all its methods are going to return early
10
+ # so it will be impossible to check if it actually works
11
+ end
12
+ end
13
+
6
14
  describe '#handle' do
7
15
  let(:properties) { OpenStruct.new(message_id: "1") }
8
16
  let(:payload) { "{}" }
@@ -83,12 +83,14 @@ describe Hutch::Worker do
83
83
  it 'passes the message to the consumer' do
84
84
  expect(consumer_instance).to receive(:process).
85
85
  with(an_instance_of(Hutch::Message))
86
+ expect(consumer_instance).to receive(:message_rejected?).and_return(false)
86
87
  worker.handle_message(consumer, delivery_info, properties, payload)
87
88
  end
88
89
 
89
90
  it 'acknowledges the message' do
90
91
  allow(consumer_instance).to receive(:process)
91
92
  expect(broker).to receive(:ack).with(delivery_info.delivery_tag)
93
+ expect(consumer_instance).to receive(:message_rejected?).and_return(false)
92
94
  worker.handle_message(consumer, delivery_info, properties, payload)
93
95
  end
94
96
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hutch
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Harry Marr
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-03-18 00:00:00.000000000 Z
12
+ date: 2022-12-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bunny
@@ -185,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
185
185
  - !ruby/object:Gem::Version
186
186
  version: '0'
187
187
  requirements: []
188
- rubygems_version: 3.1.4
188
+ rubygems_version: 3.3.7
189
189
  signing_key:
190
190
  specification_version: 4
191
191
  summary: Opinionated asynchronous inter-service communication using RabbitMQ