Class: Gruf::Interceptors::ActiveRecord::ConnectionReset

Inherits:
ServerInterceptor show all
Defined in:
lib/gruf/interceptors/active_record/connection_reset.rb

Overview

Resets the ActiveRecord connection to maintain accurate connected state in the thread pool

Instance Attribute Summary

Attributes inherited from Base

#error, #options, #request

Instance Method Summary collapse

Methods included from Errors::Helpers

#fail!

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Gruf::Interceptors::Base

Instance Method Details

#callObject

Reset any ActiveRecord connections after a gRPC service is called. Because of the way gRPC manages its connection pool, we need to ensure that this is done to properly



29
30
31
32
33
34
35
36
37
# File 'lib/gruf/interceptors/active_record/connection_reset.rb', line 29

def call
  if enabled?
    target_classes.each { |klass| klass.establish_connection unless klass.connection.active? }
  end

  yield
ensure
  target_classes.each(&:clear_active_connections!) if enabled?
end