Skip to content

Instantly share code, notes, and snippets.

@sat0yu
Created September 28, 2019 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sat0yu/22676846bf8b6125afadb08f956844cf to your computer and use it in GitHub Desktop.
Save sat0yu/22676846bf8b6125afadb08f956844cf to your computer and use it in GitHub Desktop.
class ActiveRecordWithConnectionInterceptor < ::GRPC::ServerInterceptor
def request_response(**)
# ref: https://github.com/rails/rails/blob/5-2-stable/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb#L54-L56
::ActiveRecord::Base.connection_pool.with_connection do
yield
end
end
alias_method :server_streamer, :request_response
alias_method :client_streamer, :request_response
alias_method :bidi_streamer, :request_response
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment