pwwka 0.19.0 → 0.20.0
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/lib/pwwka/receiver.rb +1 -0
- data/lib/pwwka/transmitter.rb +4 -2
- data/lib/pwwka/version.rb +1 -1
- data/spec/unit/receiver_spec.rb +36 -7
- data/spec/unit/transmitter_spec.rb +37 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f3112d40e1055cea1ee6a8d1335933a40d8bb8676eee3e59f8143c5bcc5ec945
|
4
|
+
data.tar.gz: 3ff10bab3455edb15cbca6ae7d7ef67c2e9a6ad58fb678fa31a3b8cd74f9f648
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 77c1ba64026ff171573ac521e0245dadf23aa7a9f76abafe1205f79af3753d78a59139bc7c93565a5f1bc86fbf5184e74d8dd54c665ba281e0329df37f980b91
|
7
|
+
data.tar.gz: 65fe34a0aca0e31ed8210939268df9852c986a34d60d198ed785d43e6a49a7da7f57435bb7d37b4ecb456165301d3569667aa80f029441ab2950174cb90671c7
|
data/lib/pwwka/receiver.rb
CHANGED
data/lib/pwwka/transmitter.rb
CHANGED
@@ -121,10 +121,11 @@ module Pwwka
|
|
121
121
|
)
|
122
122
|
logf "START Transmitting Message on id[%{id}] %{routing_key} -> %{payload}", id: publish_options.message_id, routing_key: routing_key, payload: payload
|
123
123
|
channel_connector.topic_exchange.publish(payload.to_json, publish_options.to_h)
|
124
|
-
channel_connector.connection_close
|
125
124
|
# if it gets this far it has succeeded
|
126
125
|
logf "END Transmitting Message on id[%{id}] %{routing_key} -> %{payload}", id: publish_options.message_id, routing_key: routing_key, payload: payload
|
127
126
|
true
|
127
|
+
ensure
|
128
|
+
channel_connector.connection_close
|
128
129
|
end
|
129
130
|
|
130
131
|
|
@@ -140,10 +141,11 @@ module Pwwka
|
|
140
141
|
logf "START Transmitting Delayed Message on id[%{id}] %{routing_key} -> %{payload}", id: publish_options.message_id, routing_key: routing_key, payload: payload
|
141
142
|
channel_connector.create_delayed_queue
|
142
143
|
channel_connector.delayed_exchange.publish(payload.to_json,publish_options.to_h)
|
143
|
-
channel_connector.connection_close
|
144
144
|
# if it gets this far it has succeeded
|
145
145
|
logf "END Transmitting Delayed Message on id[%{id}] %{routing_key} -> %{payload}", id: publish_options.message_id, routing_key: routing_key, payload: payload
|
146
146
|
true
|
147
|
+
ensure
|
148
|
+
channel_connector.connection_close
|
147
149
|
end
|
148
150
|
|
149
151
|
end
|
data/lib/pwwka/version.rb
CHANGED
data/spec/unit/receiver_spec.rb
CHANGED
@@ -1,17 +1,46 @@
|
|
1
1
|
require 'spec_helper.rb'
|
2
2
|
|
3
3
|
describe Pwwka::Receiver do
|
4
|
-
describe "#new" do
|
5
|
-
let(:
|
4
|
+
describe "#new" do
|
5
|
+
let(:handler_klass) { double('HandlerKlass') }
|
6
|
+
let(:channel_connector) { double(Pwwka::ChannelConnector, topic_exchange: topic_exchange, channel: channel)}
|
7
|
+
let(:topic_exchange) { double("topic exchange") }
|
8
|
+
let(:channel) { double('channel', queue: queue) }
|
9
|
+
let(:queue) { double('queue') }
|
10
|
+
let(:queue_name) { 'test_queue_name' }
|
11
|
+
|
12
|
+
subject {
|
13
|
+
described_class.subscribe(
|
14
|
+
handler_klass,
|
15
|
+
queue_name
|
16
|
+
)
|
17
|
+
}
|
6
18
|
|
7
19
|
before do
|
8
|
-
allow(Pwwka::ChannelConnector).to receive(:new).
|
9
|
-
allow(
|
10
|
-
allow(channel_connector).to receive(:
|
20
|
+
allow(Pwwka::ChannelConnector).to receive(:new).and_return(channel_connector)
|
21
|
+
allow(handler_klass).to receive(:handle!)
|
22
|
+
allow(channel_connector).to receive(:connection_close)
|
23
|
+
allow(queue).to receive(:bind)
|
24
|
+
allow(queue).to receive(:subscribe).and_yield({}, {}, '{}')
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'sets the correct connection_name' do
|
28
|
+
subject
|
29
|
+
expect(Pwwka::ChannelConnector).to have_received(:new).with(prefetch: nil, connection_name: "c: #{queue_name}")
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'closes the conenction on an error' do
|
33
|
+
error = 'oh no'
|
34
|
+
allow(handler_klass).to receive(:handle!).and_raise(error)
|
35
|
+
begin; subject; rescue; end
|
36
|
+
expect(channel_connector).to have_received(:connection_close)
|
11
37
|
end
|
12
38
|
|
13
|
-
it
|
14
|
-
|
39
|
+
it 'logs on interrupt' do
|
40
|
+
allow(handler_klass).to receive(:handle!).and_raise(Interrupt)
|
41
|
+
allow(described_class).to receive(:info)
|
42
|
+
begin; subject; rescue; end
|
43
|
+
expect(described_class).to have_received(:info).with(/Interrupting queue #{queue_name}/)
|
15
44
|
end
|
16
45
|
end
|
17
46
|
end
|
@@ -327,8 +327,25 @@ describe Pwwka::Transmitter do
|
|
327
327
|
expect(channel_connector).to have_received(:connection_close)
|
328
328
|
end
|
329
329
|
|
330
|
-
context
|
330
|
+
context 'when an error is raised' do
|
331
|
+
subject { transmitter.send_message!(payload,routing_key) }
|
332
|
+
let(:error) { 'oh no' }
|
333
|
+
|
334
|
+
before do
|
335
|
+
allow(topic_exchange).to receive(:publish).and_raise(error)
|
336
|
+
end
|
337
|
+
|
338
|
+
it 'should raise the error' do
|
339
|
+
expect { subject } .to raise_error(error)
|
340
|
+
end
|
331
341
|
|
342
|
+
it 'should close the channel connector' do
|
343
|
+
begin; subject; rescue; end
|
344
|
+
expect(channel_connector).to have_received(:connection_close)
|
345
|
+
end
|
346
|
+
end
|
347
|
+
|
348
|
+
context "with only basic required arguments" do
|
332
349
|
before do
|
333
350
|
transmitter.send_message!(payload,routing_key)
|
334
351
|
end
|
@@ -337,6 +354,7 @@ describe Pwwka::Transmitter do
|
|
337
354
|
let(:exchange) { topic_exchange }
|
338
355
|
end
|
339
356
|
end
|
357
|
+
|
340
358
|
context "with everything overridden" do
|
341
359
|
before do
|
342
360
|
transmitter.send_message!(
|
@@ -369,6 +387,24 @@ describe Pwwka::Transmitter do
|
|
369
387
|
expect(channel_connector).to have_received(:create_delayed_queue)
|
370
388
|
end
|
371
389
|
|
390
|
+
context 'when an error is raised' do
|
391
|
+
subject { transmitter.send_delayed_message!(payload,routing_key) }
|
392
|
+
let(:error) { 'oh no' }
|
393
|
+
|
394
|
+
before do
|
395
|
+
allow(delayed_exchange).to receive(:publish).and_raise(error)
|
396
|
+
end
|
397
|
+
|
398
|
+
it 'should raise the error' do
|
399
|
+
expect { subject } .to raise_error(error)
|
400
|
+
end
|
401
|
+
|
402
|
+
it 'should close the channel connector' do
|
403
|
+
begin; subject; rescue; end
|
404
|
+
expect(channel_connector).to have_received(:connection_close)
|
405
|
+
end
|
406
|
+
end
|
407
|
+
|
372
408
|
context "with only basic required arguments" do
|
373
409
|
before do
|
374
410
|
transmitter.send_delayed_message!(payload,routing_key,5_000)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pwwka
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.20.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stitch Fix Engineering
|
@@ -15,7 +15,7 @@ authors:
|
|
15
15
|
autorequire:
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
|
-
date: 2018-12-
|
18
|
+
date: 2018-12-20 00:00:00.000000000 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: bunny
|