Class: Gruf::Hooks::ActiveRecord::ConnectionReset

Inherits:
Base
  • Object
show all
Defined in:
lib/gruf/hooks/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

#options, #service

Instance Method Summary collapse

Methods inherited from Base

#initialize, #method_key, #service_key, #setup

Methods included from Loggable

#logger

Constructor Details

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

Instance Method Details

#after(_success, _response, _call_signature, _request, _call) ⇒ Object

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

the call itself

Parameters:

  • _success (Boolean)

    Whether or not the call was successful

  • _response (Object)

    The protobuf response object

  • _call_signature (Symbol)

    The gRPC method on the service that was called

  • _request (Object)

    The protobuf request object

  • _call (GRPC::ActiveCall)

    the gRPC core active call object, which represents marshalled data for



35
36
37
# File 'lib/gruf/hooks/active_record/connection_reset.rb', line 35

def after(_success, _response, _call_signature, _request, _call)
  ::ActiveRecord::Base.clear_active_connections! if enabled?
end