hutch 0.21.0 → 0.22.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.yardopts +5 -0
- data/CHANGELOG.md +55 -1
- data/Gemfile +1 -1
- data/README.md +2 -2
- data/Rakefile +8 -1
- data/hutch.gemspec +4 -1
- data/lib/hutch.rb +11 -8
- data/lib/hutch/adapters/march_hare.rb +1 -1
- data/lib/hutch/broker.rb +89 -110
- data/lib/hutch/cli.rb +34 -10
- data/lib/hutch/config.rb +192 -55
- data/lib/hutch/error_handlers/sentry.rb +1 -1
- data/lib/hutch/logging.rb +1 -0
- data/lib/hutch/publisher.rb +75 -0
- data/lib/hutch/version.rb +1 -1
- data/lib/hutch/waiter.rb +41 -0
- data/lib/hutch/worker.rb +8 -60
- data/lib/yard-settings/handler.rb +38 -0
- data/lib/yard-settings/yard-settings.rb +2 -0
- data/spec/hutch/broker_spec.rb +107 -64
- data/spec/hutch/cli_spec.rb +3 -3
- data/spec/hutch/config_spec.rb +60 -22
- data/spec/hutch/error_handlers/sentry_spec.rb +1 -1
- data/spec/hutch/logger_spec.rb +12 -6
- data/spec/hutch/waiter_spec.rb +33 -0
- data/spec/hutch/worker_spec.rb +13 -2
- data/spec/spec_helper.rb +7 -5
- data/templates/default/class/html/settings.erb +0 -0
- data/templates/default/class/setup.rb +4 -0
- data/templates/default/fulldoc/html/css/hutch.css +13 -0
- data/templates/default/layout/html/setup.rb +7 -0
- data/templates/default/method_details/html/settings.erb +5 -0
- data/templates/default/method_details/setup.rb +4 -0
- data/templates/default/method_details/text/settings.erb +0 -0
- data/templates/default/module/html/settings.erb +40 -0
- data/templates/default/module/setup.rb +4 -0
- metadata +63 -5
data/spec/hutch/config_spec.rb
CHANGED
@@ -4,23 +4,37 @@ require 'tempfile'
|
|
4
4
|
describe Hutch::Config do
|
5
5
|
let(:new_value) { 'not-localhost' }
|
6
6
|
|
7
|
+
before do
|
8
|
+
Hutch::Config.initialize
|
9
|
+
end
|
10
|
+
|
7
11
|
describe '.get' do
|
8
12
|
context 'for valid attributes' do
|
9
13
|
subject { Hutch::Config.get(:mq_host) }
|
10
14
|
|
11
15
|
context 'with no overridden value' do
|
12
|
-
it { is_expected.to eq('
|
16
|
+
it { is_expected.to eq('127.0.0.1') }
|
13
17
|
end
|
14
18
|
|
15
19
|
context 'with an overridden value' do
|
16
|
-
before
|
20
|
+
before do
|
21
|
+
allow(Hutch::Config).to receive_messages(
|
22
|
+
user_config: { mq_host: new_value }
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
17
26
|
it { is_expected.to eq(new_value) }
|
18
27
|
end
|
19
28
|
end
|
20
29
|
|
21
30
|
context 'for invalid attributes' do
|
22
|
-
let(:invalid_get)
|
23
|
-
|
31
|
+
let(:invalid_get) do
|
32
|
+
-> { Hutch::Config.get(:invalid_attr) }
|
33
|
+
end
|
34
|
+
|
35
|
+
specify do
|
36
|
+
expect(invalid_get).to raise_error Hutch::UnknownAttributeError
|
37
|
+
end
|
24
38
|
end
|
25
39
|
end
|
26
40
|
|
@@ -35,8 +49,13 @@ describe Hutch::Config do
|
|
35
49
|
end
|
36
50
|
|
37
51
|
context 'for invalid attributes' do
|
38
|
-
let(:invalid_set)
|
39
|
-
|
52
|
+
let(:invalid_set) do
|
53
|
+
-> { Hutch::Config.set(:invalid_attr, new_value) }
|
54
|
+
end
|
55
|
+
|
56
|
+
specify do
|
57
|
+
expect(invalid_set).to raise_error Hutch::UnknownAttributeError
|
58
|
+
end
|
40
59
|
end
|
41
60
|
end
|
42
61
|
|
@@ -49,9 +68,33 @@ describe Hutch::Config do
|
|
49
68
|
end
|
50
69
|
|
51
70
|
context 'for an invalid attribute' do
|
52
|
-
let(:invalid_getter) { ->{ Hutch::Config.invalid_attr } }
|
71
|
+
let(:invalid_getter) { -> { Hutch::Config.invalid_attr } }
|
53
72
|
specify { expect(invalid_getter).to raise_error NoMethodError }
|
54
73
|
end
|
74
|
+
|
75
|
+
context 'for an ENV-overriden value attribute' do
|
76
|
+
around do |example|
|
77
|
+
ENV['HUTCH_MQ_HOST'] = 'example.com'
|
78
|
+
ENV['HUTCH_MQ_PORT'] = '10001'
|
79
|
+
ENV['HUTCH_MQ_TLS'] = 'true'
|
80
|
+
example.run
|
81
|
+
ENV.delete('HUTCH_MQ_HOST')
|
82
|
+
ENV.delete('HUTCH_MQ_PORT')
|
83
|
+
ENV.delete('HUTCH_MQ_TLS')
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'returns the override' do
|
87
|
+
expect(Hutch::Config.mq_host).to eq 'example.com'
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'returns the override for integers' do
|
91
|
+
expect(Hutch::Config.mq_port).to eq 10_001
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'returns the override for booleans' do
|
95
|
+
expect(Hutch::Config.mq_tls).to eq true
|
96
|
+
end
|
97
|
+
end
|
55
98
|
end
|
56
99
|
|
57
100
|
describe 'a magic setter' do
|
@@ -63,7 +106,7 @@ describe Hutch::Config do
|
|
63
106
|
end
|
64
107
|
|
65
108
|
context 'for an invalid attribute' do
|
66
|
-
let(:invalid_setter) { ->{ Hutch::Config.invalid_attr = new_value } }
|
109
|
+
let(:invalid_setter) { -> { Hutch::Config.invalid_attr = new_value } }
|
67
110
|
specify { expect(invalid_setter).to raise_error NoMethodError }
|
68
111
|
end
|
69
112
|
end
|
@@ -81,9 +124,9 @@ describe Hutch::Config do
|
|
81
124
|
context 'when an attribute is invalid' do
|
82
125
|
let(:config_data) { { random_attribute: 'socks' } }
|
83
126
|
it 'raises an error' do
|
84
|
-
expect
|
127
|
+
expect do
|
85
128
|
Hutch::Config.load_from_file(file)
|
86
|
-
|
129
|
+
end.to raise_error(NoMethodError)
|
87
130
|
end
|
88
131
|
end
|
89
132
|
|
@@ -96,26 +139,21 @@ describe Hutch::Config do
|
|
96
139
|
expect(Hutch::Config.mq_username).to eq username
|
97
140
|
end
|
98
141
|
end
|
99
|
-
end
|
100
142
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
143
|
+
context 'when using ERB' do
|
144
|
+
let(:host) { 'localhost' }
|
145
|
+
let(:file) do
|
146
|
+
Tempfile.new('configs.yaml').tap do |t|
|
147
|
+
t.write(config_contents)
|
148
|
+
t.rewind
|
149
|
+
end
|
108
150
|
end
|
109
|
-
end
|
110
|
-
|
111
|
-
context 'when using ERb' do
|
112
151
|
let(:config_contents) do
|
113
152
|
<<-YAML
|
114
153
|
mq_host: 'localhost'
|
115
154
|
mq_username: '<%= "calvin" %>'
|
116
155
|
YAML
|
117
156
|
end
|
118
|
-
|
119
157
|
it 'loads in the config data' do
|
120
158
|
Hutch::Config.load_from_file(file)
|
121
159
|
expect(Hutch::Config.mq_host).to eq host
|
@@ -13,7 +13,7 @@ describe Hutch::ErrorHandlers::Sentry do
|
|
13
13
|
end
|
14
14
|
|
15
15
|
it "logs the error to Sentry" do
|
16
|
-
expect(Raven).to receive(:capture_exception).with(error)
|
16
|
+
expect(Raven).to receive(:capture_exception).with(error, extra: { payload: "{}" })
|
17
17
|
error_handler.handle("1", "{}", double, error)
|
18
18
|
end
|
19
19
|
end
|
data/spec/hutch/logger_spec.rb
CHANGED
@@ -3,24 +3,30 @@ require 'spec_helper'
|
|
3
3
|
describe Hutch::Logging do
|
4
4
|
let(:dummy_object) do
|
5
5
|
class DummyObject
|
6
|
-
include
|
6
|
+
include described_class
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
10
|
describe '#logger' do
|
11
|
+
around do |example|
|
12
|
+
old_logger = described_class.logger
|
13
|
+
described_class.setup_logger
|
14
|
+
example.run
|
15
|
+
described_class.logger = old_logger
|
16
|
+
end
|
17
|
+
|
11
18
|
context 'with the default logger' do
|
12
|
-
subject {
|
19
|
+
subject { described_class.logger }
|
13
20
|
|
14
21
|
it { is_expected.to be_instance_of(Logger) }
|
15
22
|
end
|
16
23
|
|
17
24
|
context 'with a custom logger' do
|
18
|
-
let(:dummy_logger) { double("Dummy logger"
|
19
|
-
after { Hutch::Logging.setup_logger }
|
25
|
+
let(:dummy_logger) { double("Dummy logger") }
|
20
26
|
|
21
27
|
it "users the custom logger" do
|
22
|
-
|
23
|
-
expect(
|
28
|
+
described_class.logger = dummy_logger
|
29
|
+
expect(described_class.logger).to eq(dummy_logger)
|
24
30
|
end
|
25
31
|
end
|
26
32
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'hutch/waiter'
|
2
|
+
|
3
|
+
RSpec.describe Hutch::Waiter do
|
4
|
+
describe '.wait_until_signaled' do
|
5
|
+
let(:pid) { Process.pid }
|
6
|
+
def start_kill_thread(signal)
|
7
|
+
Thread.new do
|
8
|
+
# sleep allows the worker time to set up the signal handling
|
9
|
+
# before the kill signal is sent.
|
10
|
+
sleep 0.001
|
11
|
+
Process.kill signal, pid
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
%w(QUIT TERM INT).each do |signal|
|
16
|
+
context "a #{signal} signal is received" do
|
17
|
+
it "logs that hutch is stopping" do
|
18
|
+
expect(Hutch::Logging.logger).to receive(:info)
|
19
|
+
.with("caught sig#{signal.downcase}, stopping hutch...")
|
20
|
+
|
21
|
+
start_kill_thread(signal)
|
22
|
+
described_class.wait_until_signaled
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe described_class::SHUTDOWN_SIGNALS do
|
29
|
+
it "includes only things in Signal.list.keys" do
|
30
|
+
expect(described_class).to eq(described_class & Signal.list.keys)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/spec/hutch/worker_spec.rb
CHANGED
@@ -7,7 +7,19 @@ describe Hutch::Worker do
|
|
7
7
|
get_serializer: nil) }
|
8
8
|
let(:consumers) { [consumer, double('Consumer')] }
|
9
9
|
let(:broker) { Hutch::Broker.new }
|
10
|
-
|
10
|
+
let(:setup_procs) { Array.new(2) { Proc.new {} } }
|
11
|
+
subject(:worker) { Hutch::Worker.new(broker, consumers, setup_procs) }
|
12
|
+
|
13
|
+
describe ".#run" do
|
14
|
+
it "calls each setup proc" do
|
15
|
+
setup_procs.each { |prc| expect(prc).to receive(:call) }
|
16
|
+
allow(worker).to receive(:setup_queues)
|
17
|
+
allow(Hutch::Waiter).to receive(:wait_until_signaled)
|
18
|
+
allow(broker).to receive(:stop)
|
19
|
+
|
20
|
+
worker.run
|
21
|
+
end
|
22
|
+
end
|
11
23
|
|
12
24
|
describe '#setup_queues' do
|
13
25
|
it 'sets up queues for each of the consumers' do
|
@@ -20,7 +32,6 @@ describe Hutch::Worker do
|
|
20
32
|
|
21
33
|
describe '#setup_queue' do
|
22
34
|
let(:queue) { double('Queue', bind: nil, subscribe: nil) }
|
23
|
-
before { allow(worker).to receive_messages(consumer_queue: queue) }
|
24
35
|
before { allow(broker).to receive_messages(queue: queue, bind_queue: nil) }
|
25
36
|
|
26
37
|
it 'creates a queue' do
|
data/spec/spec_helper.rb
CHANGED
@@ -13,8 +13,10 @@ require 'raven'
|
|
13
13
|
require 'hutch'
|
14
14
|
require 'logger'
|
15
15
|
|
16
|
+
# set logger to be a null logger
|
17
|
+
Hutch::Logging.logger = Logger.new(File::NULL)
|
18
|
+
|
16
19
|
RSpec.configure do |config|
|
17
|
-
config.before(:all) { Hutch::Config.log_level = Logger::FATAL }
|
18
20
|
config.raise_errors_for_deprecations!
|
19
21
|
|
20
22
|
if defined?(JRUBY_VERSION)
|
@@ -22,6 +24,10 @@ RSpec.configure do |config|
|
|
22
24
|
else
|
23
25
|
config.filter_run_excluding adapter: :march_hare
|
24
26
|
end
|
27
|
+
|
28
|
+
config.mock_with :rspec do |mocks|
|
29
|
+
mocks.verify_partial_doubles = true
|
30
|
+
end
|
25
31
|
end
|
26
32
|
|
27
33
|
# Constants (classes, etc) defined within a block passed to this method
|
@@ -34,7 +40,3 @@ ensure
|
|
34
40
|
Object.send(:remove_const, constant)
|
35
41
|
end
|
36
42
|
end
|
37
|
-
|
38
|
-
def deep_copy(obj)
|
39
|
-
Marshal.load(Marshal.dump(obj))
|
40
|
-
end
|
File without changes
|
File without changes
|
@@ -0,0 +1,40 @@
|
|
1
|
+
<% if object['setting_rows'] %>
|
2
|
+
<h2>
|
3
|
+
Configuration
|
4
|
+
</h2>
|
5
|
+
|
6
|
+
<div class="tags">
|
7
|
+
<table border="1" class="settings">
|
8
|
+
<thead>
|
9
|
+
<tr>
|
10
|
+
<th>
|
11
|
+
Setting name
|
12
|
+
</th>
|
13
|
+
<th>
|
14
|
+
Default value
|
15
|
+
</th>
|
16
|
+
<th>
|
17
|
+
Type
|
18
|
+
</th>
|
19
|
+
<th>
|
20
|
+
ENV variable
|
21
|
+
</th>
|
22
|
+
<th>
|
23
|
+
Description
|
24
|
+
</th>
|
25
|
+
</tr>
|
26
|
+
</thead>
|
27
|
+
<tbody>
|
28
|
+
<% for setting in object['setting_rows'] %>
|
29
|
+
<tr>
|
30
|
+
<td><tt><%= resolve_links "{Hutch::Config##{setting[:name]} #{setting[:name]}}" %></tt></td>
|
31
|
+
<td><%= setting[:default_value] %></td>
|
32
|
+
<td><%= setting[:type] %></td>
|
33
|
+
<td><tt>HUTCH_<%= setting[:name].upcase %></tt></td>
|
34
|
+
<td><%= html_markup_markdown setting[:first_line_of_description] %></td>
|
35
|
+
</tr>
|
36
|
+
<% end %>
|
37
|
+
</tbody>
|
38
|
+
</table>
|
39
|
+
</div>
|
40
|
+
<% end %>
|
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.
|
4
|
+
version: 0.22.1
|
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-
|
11
|
+
date: 2016-06-06 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.
|
19
|
+
version: 2.3.1
|
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.
|
26
|
+
version: 2.3.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: carrot-top
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,6 +94,48 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
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
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
97
139
|
description: Hutch is a Ruby library for enabling asynchronous inter-service communication
|
98
140
|
using RabbitMQ.
|
99
141
|
email:
|
@@ -105,6 +147,7 @@ extra_rdoc_files: []
|
|
105
147
|
files:
|
106
148
|
- ".gitignore"
|
107
149
|
- ".travis.yml"
|
150
|
+
- ".yardopts"
|
108
151
|
- CHANGELOG.md
|
109
152
|
- Gemfile
|
110
153
|
- Guardfile
|
@@ -133,13 +176,17 @@ files:
|
|
133
176
|
- lib/hutch/exceptions.rb
|
134
177
|
- lib/hutch/logging.rb
|
135
178
|
- lib/hutch/message.rb
|
179
|
+
- lib/hutch/publisher.rb
|
136
180
|
- lib/hutch/serializers/identity.rb
|
137
181
|
- lib/hutch/serializers/json.rb
|
138
182
|
- lib/hutch/tracers.rb
|
139
183
|
- lib/hutch/tracers/newrelic.rb
|
140
184
|
- lib/hutch/tracers/null_tracer.rb
|
141
185
|
- lib/hutch/version.rb
|
186
|
+
- lib/hutch/waiter.rb
|
142
187
|
- lib/hutch/worker.rb
|
188
|
+
- lib/yard-settings/handler.rb
|
189
|
+
- lib/yard-settings/yard-settings.rb
|
143
190
|
- spec/hutch/broker_spec.rb
|
144
191
|
- spec/hutch/cli_spec.rb
|
145
192
|
- spec/hutch/config_spec.rb
|
@@ -151,9 +198,19 @@ files:
|
|
151
198
|
- spec/hutch/logger_spec.rb
|
152
199
|
- spec/hutch/message_spec.rb
|
153
200
|
- spec/hutch/serializers/json_spec.rb
|
201
|
+
- spec/hutch/waiter_spec.rb
|
154
202
|
- spec/hutch/worker_spec.rb
|
155
203
|
- spec/hutch_spec.rb
|
156
204
|
- spec/spec_helper.rb
|
205
|
+
- templates/default/class/html/settings.erb
|
206
|
+
- templates/default/class/setup.rb
|
207
|
+
- templates/default/fulldoc/html/css/hutch.css
|
208
|
+
- templates/default/layout/html/setup.rb
|
209
|
+
- templates/default/method_details/html/settings.erb
|
210
|
+
- templates/default/method_details/setup.rb
|
211
|
+
- templates/default/method_details/text/settings.erb
|
212
|
+
- templates/default/module/html/settings.erb
|
213
|
+
- templates/default/module/setup.rb
|
157
214
|
homepage: https://github.com/gocardless/hutch
|
158
215
|
licenses:
|
159
216
|
- MIT
|
@@ -174,7 +231,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
174
231
|
version: '0'
|
175
232
|
requirements: []
|
176
233
|
rubyforge_project:
|
177
|
-
rubygems_version: 2.
|
234
|
+
rubygems_version: 2.5.1
|
178
235
|
signing_key:
|
179
236
|
specification_version: 4
|
180
237
|
summary: Easy inter-service communication using RabbitMQ.
|
@@ -190,6 +247,7 @@ test_files:
|
|
190
247
|
- spec/hutch/logger_spec.rb
|
191
248
|
- spec/hutch/message_spec.rb
|
192
249
|
- spec/hutch/serializers/json_spec.rb
|
250
|
+
- spec/hutch/waiter_spec.rb
|
193
251
|
- spec/hutch/worker_spec.rb
|
194
252
|
- spec/hutch_spec.rb
|
195
253
|
- spec/spec_helper.rb
|