Class: Rabbitek::Server::Hooks::ActiveRecordConnectionReset

Inherits:
Rabbitek::ServerHook show all
Defined in:
lib/rabbitek/server/hooks/active_record_connection_reset.rb

Overview

Active record connection reset to maintain correct connection state Used only in Rails < 5

Instance Method Summary collapse

Constructor Details

#initializeActiveRecordConnectionReset

Returns a new instance of ActiveRecordConnectionReset.

Raises:

  • (ArgumentError)


12
13
14
# File 'lib/rabbitek/server/hooks/active_record_connection_reset.rb', line 12

def initialize
  raise ArgumentError, 'Use AR connection reset only in Rails < 5!' unless should_allow_hook?
end

Instance Method Details

#call(consumer, message) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/rabbitek/server/hooks/active_record_connection_reset.rb', line 16

def call(consumer, message)
  ::ActiveRecord::Base.establish_connection unless ::ActiveRecord::Base.connection.active?

  super
ensure
  ::ActiveRecord::Base.clear_active_connections!
end