pwwka 0.19.0 → 0.20.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: 5765ddd484db315254a41e9d4e445ca89d7fef1af2f24619de73bf1699f5ae5e
4
- data.tar.gz: 7544a009754d7094524a6732a5ea40844abb324e14e97fcbaccb10c3f28f56aa
3
+ metadata.gz: f3112d40e1055cea1ee6a8d1335933a40d8bb8676eee3e59f8143c5bcc5ec945
4
+ data.tar.gz: 3ff10bab3455edb15cbca6ae7d7ef67c2e9a6ad58fb678fa31a3b8cd74f9f648
5
5
  SHA512:
6
- metadata.gz: 9e86c5de727b0d355fa2af8cb5bd3bc99da6f34d539d3f65f025012f47e9fa7517d91d571cb28d778f3dabcb3caa88498a5ad8ce1509e42f941f05d34d6eb985
7
- data.tar.gz: 2cfedd5609d5c3b13c8beb42a0873798cc6ae6d5a4309a5bb15138b88e4e6a1f259689494a23254c70693d4f7f46f7e7d3a894cfff6d794c5747fecdf24aa4d8
6
+ metadata.gz: 77c1ba64026ff171573ac521e0245dadf23aa7a9f76abafe1205f79af3753d78a59139bc7c93565a5f1bc86fbf5184e74d8dd54c665ba281e0329df37f980b91
7
+ data.tar.gz: 65fe34a0aca0e31ed8210939268df9852c986a34d60d198ed785d43e6a49a7da7f57435bb7d37b4ecb456165301d3569667aa80f029441ab2950174cb90671c7
@@ -47,6 +47,7 @@ module Pwwka
47
47
  rescue Interrupt => _
48
48
  # TODO: trap TERM within channel.work_pool
49
49
  info "Interrupting queue #{queue_name} subscriber safely"
50
+ ensure
50
51
  receiver.channel_connector.connection_close
51
52
  end
52
53
  return receiver
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Pwwka
2
- VERSION = '0.19.0'
2
+ VERSION = '0.20.0'
3
3
  end
@@ -1,17 +1,46 @@
1
1
  require 'spec_helper.rb'
2
2
 
3
3
  describe Pwwka::Receiver do
4
- describe "#new" do
5
- let(:channel_connector) { double(Pwwka::ChannelConnector)}
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).with(prefetch: nil, connection_name: "c: test_queue_name").and_return(channel_connector)
9
- allow(channel_connector).to receive(:channel)
10
- allow(channel_connector).to receive(:topic_exchange)
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 "should set the connection_name" do
14
- Pwwka::Receiver.new("test_queue_name", "test.routing.key")
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 "with only basic required arguments" do
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.19.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-10 00:00:00.000000000 Z
18
+ date: 2018-12-20 00:00:00.000000000 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: bunny