action_subscriber 5.1.0 → 5.1.1.pre0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/action_subscriber/middleware/env.rb +11 -3
- data/lib/action_subscriber/middleware/error_handler.rb +8 -1
- data/lib/action_subscriber/rspec.rb +10 -1
- data/lib/action_subscriber/version.rb +1 -1
- data/spec/lib/action_subscriber/middleware/error_handler_spec.rb +37 -4
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8cc908c265f2f8b2ae3ae18054c8cb44285c3a8
|
4
|
+
data.tar.gz: 866a49421a1e0124206c547094a7766d12478afb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7dd674665092e3a9a65716056bc7fd87892fbd56a69e9a1083cc5e79e9ccd71ecf193d527c2d861a9aa2c65b01e5586f7608bd3c067786131daf67ec65cf8724
|
7
|
+
data.tar.gz: f1cd31b1d875aab7cbb3fe5f385b187f9847ea0ec595fc6e52c3ee0d1cfeb5064c423fd7f62e132fb18bf39912a6e41749ffe51c878a4a95772d516f537f1988
|
@@ -46,14 +46,21 @@ module ActionSubscriber
|
|
46
46
|
|
47
47
|
def acknowledge
|
48
48
|
fail ::RuntimeError, "you can't acknowledge messages under the polling API" unless @channel
|
49
|
+
return true if @has_been_acked
|
49
50
|
acknowledge_multiple_messages = false
|
50
51
|
@has_been_acked = true
|
51
52
|
@channel.ack(@delivery_tag, acknowledge_multiple_messages)
|
52
53
|
true
|
53
54
|
end
|
54
55
|
|
56
|
+
def channel_open?
|
57
|
+
return false unless @channel
|
58
|
+
@channel.open?
|
59
|
+
end
|
60
|
+
|
55
61
|
def nack
|
56
62
|
fail ::RuntimeError, "you can't acknowledge messages under the polling API" unless @channel
|
63
|
+
return true if @has_been_nacked
|
57
64
|
nack_multiple_messages = false
|
58
65
|
requeue_message = true
|
59
66
|
@has_been_nacked = true
|
@@ -63,6 +70,7 @@ module ActionSubscriber
|
|
63
70
|
|
64
71
|
def reject
|
65
72
|
fail ::RuntimeError, "you can't acknowledge messages under the polling API" unless @channel
|
73
|
+
return true if @has_been_rejected
|
66
74
|
requeue_message = true
|
67
75
|
@has_been_rejected = true
|
68
76
|
@channel.reject(@delivery_tag, requeue_message)
|
@@ -70,15 +78,15 @@ module ActionSubscriber
|
|
70
78
|
end
|
71
79
|
|
72
80
|
def safe_acknowledge
|
73
|
-
acknowledge if uses_acknowledgements? &&
|
81
|
+
acknowledge if uses_acknowledgements? && channel_open? && !has_used_delivery_tag?
|
74
82
|
end
|
75
83
|
|
76
84
|
def safe_nack
|
77
|
-
nack if uses_acknowledgements? &&
|
85
|
+
nack if uses_acknowledgements? && channel_open? && !has_used_delivery_tag?
|
78
86
|
end
|
79
87
|
|
80
88
|
def safe_reject
|
81
|
-
reject if uses_acknowledgements? &&
|
89
|
+
reject if uses_acknowledgements? && channel_open? && !has_used_delivery_tag?
|
82
90
|
end
|
83
91
|
|
84
92
|
def to_hash
|
@@ -22,7 +22,14 @@ module ActionSubscriber
|
|
22
22
|
logger.error { "ActionSubscriber error handler raised error, but should never raise. Error: #{inner_error}" }
|
23
23
|
end
|
24
24
|
ensure
|
25
|
-
|
25
|
+
# This second rescue is a little extreme, but we need to be very cautious here to avoid errors
|
26
|
+
# being sent back to bunny or march_hare land.
|
27
|
+
begin
|
28
|
+
# Make sure we attempt to `nack` a message that did not get processed if something fails
|
29
|
+
env.safe_nack
|
30
|
+
rescue Exception => inner_error
|
31
|
+
logger.error { "ActionSubscriber error handler raised error while nack-ing message. Error: #{inner_error}" }
|
32
|
+
end
|
26
33
|
end
|
27
34
|
end
|
28
35
|
end
|
@@ -3,10 +3,18 @@ require 'rspec/core'
|
|
3
3
|
module ActionSubscriber
|
4
4
|
module RSpec
|
5
5
|
class FakeChannel # A class that quacks like a RabbitMQ Channel
|
6
|
+
def initialize(opts = {})
|
7
|
+
@open = opts.fetch(:open, true)
|
8
|
+
end
|
9
|
+
|
6
10
|
def ack(delivery_tag, acknowledge_multiple)
|
7
11
|
true
|
8
12
|
end
|
9
13
|
|
14
|
+
def open?
|
15
|
+
@open
|
16
|
+
end
|
17
|
+
|
10
18
|
def nack(delivery_tag, acknowledge_multiple, requeue_message)
|
11
19
|
true
|
12
20
|
end
|
@@ -76,9 +84,10 @@ end
|
|
76
84
|
shared_context 'action subscriber middleware env' do
|
77
85
|
let(:app) { Proc.new { |inner_env| inner_env } }
|
78
86
|
let(:env) { ActionSubscriber::Middleware::Env.new(UserSubscriber, 'encoded payload', message_properties) }
|
87
|
+
let(:channel) { ::ActionSubscriber::RSpec::FakeChannel.new }
|
79
88
|
let(:message_properties) {{
|
80
89
|
:action => :created,
|
81
|
-
:channel =>
|
90
|
+
:channel => channel,
|
82
91
|
:content_type => "text/plain",
|
83
92
|
:delivery_tag => "XYZ",
|
84
93
|
:exchange => "events",
|
@@ -9,6 +9,26 @@ describe ActionSubscriber::Middleware::ErrorHandler do
|
|
9
9
|
|
10
10
|
let(:load_error) { ::LoadError.new("Boom!") }
|
11
11
|
let(:runtime_error) { ::RuntimeError.new("Boom!") }
|
12
|
+
let(:message_properties) {{
|
13
|
+
:action => :created,
|
14
|
+
:channel => channel,
|
15
|
+
:content_type => "text/plain",
|
16
|
+
:delivery_tag => "XYZ",
|
17
|
+
:exchange => "events",
|
18
|
+
:headers => {},
|
19
|
+
:message_id => "MSG-123",
|
20
|
+
:routing_key => "amigo.user.created",
|
21
|
+
:queue => "test.amigo.user.created",
|
22
|
+
:uses_acknowledgements => true,
|
23
|
+
}}
|
24
|
+
|
25
|
+
it "calls safe_nack after successful execution" do
|
26
|
+
expect(env).to receive(:safe_nack).and_call_original
|
27
|
+
expect(env).to_not receive(:nack)
|
28
|
+
|
29
|
+
env.acknowledge
|
30
|
+
subject.call(env)
|
31
|
+
end
|
12
32
|
|
13
33
|
context "when an exception occurs" do
|
14
34
|
context "LoadError" do
|
@@ -23,18 +43,31 @@ describe ActionSubscriber::Middleware::ErrorHandler do
|
|
23
43
|
|
24
44
|
context "RuntimError" do
|
25
45
|
before { allow(app).to receive(:call).and_raise(runtime_error) }
|
46
|
+
|
26
47
|
it "calls the exception handler with a RuntimeError" do
|
27
48
|
handler = ::ActionSubscriber.configuration.error_handler
|
28
49
|
expect(handler).to receive(:call).with(runtime_error, env.to_h)
|
29
50
|
|
30
51
|
subject.call(env)
|
31
52
|
end
|
32
|
-
end
|
33
53
|
|
34
|
-
|
35
|
-
|
54
|
+
it "calls safe_nack after execution" do
|
55
|
+
expect(env).to receive(:safe_nack).and_call_original
|
56
|
+
expect(env).to receive(:nack)
|
36
57
|
|
37
|
-
|
58
|
+
subject.call(env)
|
59
|
+
end
|
60
|
+
|
61
|
+
context "when the channel is closed without an ack" do
|
62
|
+
let(:channel) { ::ActionSubscriber::RSpec::FakeChannel.new(:open => false) }
|
63
|
+
|
64
|
+
it "calls safe_nack after execution" do
|
65
|
+
expect(env).to receive(:safe_nack).and_call_original
|
66
|
+
expect(env).to_not receive(:nack)
|
67
|
+
|
68
|
+
subject.call(env)
|
69
|
+
end
|
70
|
+
end
|
38
71
|
end
|
39
72
|
end
|
40
73
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: action_subscriber
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.1.
|
4
|
+
version: 5.1.1.pre0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Stien
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2018-
|
15
|
+
date: 2018-02-22 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: activesupport
|
@@ -292,12 +292,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
292
292
|
version: '0'
|
293
293
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
294
294
|
requirements:
|
295
|
-
- - "
|
295
|
+
- - ">"
|
296
296
|
- !ruby/object:Gem::Version
|
297
|
-
version:
|
297
|
+
version: 1.3.1
|
298
298
|
requirements: []
|
299
299
|
rubyforge_project:
|
300
|
-
rubygems_version: 2.
|
300
|
+
rubygems_version: 2.5.2
|
301
301
|
signing_key:
|
302
302
|
specification_version: 4
|
303
303
|
summary: ActionSubscriber is a DSL that allows a rails app to consume messages from
|