rt-tackle 1.1.2 → 1.2.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
  SHA1:
3
- metadata.gz: 63bc52d4f711f20e99c10694d51a721971263931
4
- data.tar.gz: 90c678ff964a4e1e9a0c162f1dd539951cf8bf9e
3
+ metadata.gz: f81be29c18afeff98eac2923d0b314ac755e4aa0
4
+ data.tar.gz: 97f8549bc884f7e809e2f81bf16cf0f9d06bda07
5
5
  SHA512:
6
- metadata.gz: 06e85b388d9d887761b89f32a4024bc85d0fc497f0189b16d023fa4dbdc48bd1958f84b780ff18b91215fa03977ffb385ed7fa380e581018d1ccd1e3419f5fb7
7
- data.tar.gz: 863b47df45b8f0a38e583ddd2a3dd89b4c3f91c6489b43af27d5f7b4cca1ab5f6889088bff08c176bea54cd6b3aff3c903da3f7d6793eaa2c8dccaa950bbd72f
6
+ metadata.gz: 997a247bf3e1f9fae45d4897b93af6d2fe4bf2c3ec608c74a3debd3d9bde6e0f092c5fd8502264077dfb23f8ed06815b421ee2ff0ea0be4a8606e65c8c21c5d1
7
+ data.tar.gz: 9ec4f523a1178854b0c2de2aca6cad0b11ee038a224ff77fb3fd7fa72852a96d7c15f7f8493840ab49f8e775f27ae76c0335dcd2d7b3061eee887dab3a8993cc
@@ -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
- message.log_info "Calling message processor"
45
-
46
- response = block.call(message.payload)
47
-
48
- unless @params.manual_ack?
49
- response = Tackle::ACK
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
@@ -1,3 +1,3 @@
1
1
  module Tackle
2
- VERSION = "1.1.2".freeze
2
+ VERSION = "1.2.0".freeze
3
3
  end
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.1.2
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