rt-tackle 1.1.2 → 1.2.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/tackle/consumer.rb +24 -19
- data/lib/tackle/consumer/active_record_connection_reaper.rb +31 -0
- data/lib/tackle/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f81be29c18afeff98eac2923d0b314ac755e4aa0
|
4
|
+
data.tar.gz: 97f8549bc884f7e809e2f81bf16cf0f9d06bda07
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 997a247bf3e1f9fae45d4897b93af6d2fe4bf2c3ec608c74a3debd3d9bde6e0f092c5fd8502264077dfb23f8ed06815b421ee2ff0ea0be4a8606e65c8c21c5d1
|
7
|
+
data.tar.gz: 9ec4f523a1178854b0c2de2aca6cad0b11ee038a224ff77fb3fd7fa72852a96d7c15f7f8493840ab49f8e775f27ae76c0335dcd2d7b3061eee887dab3a8993cc
|
data/lib/tackle/consumer.rb
CHANGED
@@ -7,6 +7,7 @@ module Tackle
|
|
7
7
|
require_relative "consumer/main_queue"
|
8
8
|
require_relative "consumer/delay_queue"
|
9
9
|
require_relative "consumer/dead_queue"
|
10
|
+
require_relative "consumer/active_record_connection_reaper"
|
10
11
|
|
11
12
|
class Consumer
|
12
13
|
|
@@ -41,26 +42,30 @@ module Tackle
|
|
41
42
|
end
|
42
43
|
|
43
44
|
def process_message(message, &block)
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
45
|
+
Tackle::Consumer::ActiveRecordConnectionReaper.run do
|
46
|
+
begin
|
47
|
+
message.log_info "Calling message processor"
|
48
|
+
|
49
|
+
response = block.call(message.payload)
|
50
|
+
|
51
|
+
unless @params.manual_ack?
|
52
|
+
response = Tackle::ACK
|
53
|
+
end
|
54
|
+
|
55
|
+
case response
|
56
|
+
when Tackle::ACK
|
57
|
+
message.ack
|
58
|
+
when Tackle::NACK
|
59
|
+
redeliver_message(message, "Received Tackle::NACK")
|
60
|
+
else
|
61
|
+
raise "Response must be either Tackle::ACK or Tackle::NACK"
|
62
|
+
end
|
63
|
+
rescue Exception => ex
|
64
|
+
redeliver_message(message, "Received exception '#{ex}'")
|
65
|
+
|
66
|
+
raise ex
|
67
|
+
end
|
50
68
|
end
|
51
|
-
|
52
|
-
case response
|
53
|
-
when Tackle::ACK
|
54
|
-
message.ack
|
55
|
-
when Tackle::NACK
|
56
|
-
redeliver_message(message, "Received Tackle::NACK")
|
57
|
-
else
|
58
|
-
raise "Response must be either Tackle::ACK or Tackle::NACK"
|
59
|
-
end
|
60
|
-
rescue Exception => ex
|
61
|
-
redeliver_message(message, "Received exception '#{ex}'")
|
62
|
-
|
63
|
-
raise ex
|
64
69
|
end
|
65
70
|
|
66
71
|
def redeliver_message(message, reason)
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Tackle
|
2
|
+
class Consumer
|
3
|
+
module ActiveRecordConnectionReaper
|
4
|
+
module_function
|
5
|
+
|
6
|
+
#
|
7
|
+
# In case of a database failover, the active database connection can get
|
8
|
+
# stuck and unable to re-connect.
|
9
|
+
#
|
10
|
+
# It is important to clear all active connections after when a message
|
11
|
+
# is consumed. In case of a database failover, a new fresh connection will
|
12
|
+
# be created that is able to communicate with the database properly.
|
13
|
+
#
|
14
|
+
# This technique is borrowed from Sidekiq:
|
15
|
+
#
|
16
|
+
# <https://github.com/mperham/sidekiq/blob/5-0/lib/sidekiq/middleware/server/active_record.rb>
|
17
|
+
|
18
|
+
def run
|
19
|
+
yield
|
20
|
+
ensure
|
21
|
+
#
|
22
|
+
# This is no longer necessary in Rails 5+
|
23
|
+
#
|
24
|
+
if defined?(::ActiveRecord) && ActiveRecord::VERSION::MAJOR < 5
|
25
|
+
::ActiveRecord::Base.clear_active_connections!
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/tackle/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rt-tackle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rendered Text
|
@@ -98,6 +98,7 @@ files:
|
|
98
98
|
- lib/tackle.rb
|
99
99
|
- lib/tackle/connection.rb
|
100
100
|
- lib/tackle/consumer.rb
|
101
|
+
- lib/tackle/consumer/active_record_connection_reaper.rb
|
101
102
|
- lib/tackle/consumer/dead_queue.rb
|
102
103
|
- lib/tackle/consumer/delay_queue.rb
|
103
104
|
- lib/tackle/consumer/exchange.rb
|