Module: Tackle::Consumer::ActiveRecordConnectionReaper
- Defined in:
- lib/tackle/consumer/active_record_connection_reaper.rb
Class Method Summary collapse
-
.run ⇒ Object
In case of a database failover, the active database connection can get stuck and unable to re-connect.
Class Method Details
.run ⇒ Object
In case of a database failover, the active database connection can get stuck and unable to re-connect.
It is important to clear all active connections after when a message is consumed. In case of a database failover, a new fresh connection will be created that is able to communicate with the database properly.
This technique is borrowed from Sidekiq:
<github.com/mperham/sidekiq/blob/5-0/lib/sidekiq/middleware/server/active_record.rb>
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/tackle/consumer/active_record_connection_reaper.rb', line 18 def run yield ensure # # This is no longer necessary in Rails 5+ # if defined?(::ActiveRecord) && ActiveRecord::VERSION::MAJOR < 5 ::ActiveRecord::Base.clear_active_connections! end end |