Sha256: 19a734ad19526381224a8d4e4c5df4fa7a05a725f03db68bcd56aeb407caaa63
Contents?: true
Size: 1.25 KB
Versions: 6
Compression:
Stored size: 1.25 KB
Contents
module FreshConnection module Extend module Mysql2Adapter def self.included(base) base.__send__(:attr_writer, :model_class) base.alias_method_chain :configure_connection, :fresh_connection end def select_all(arel, name = nil, binds = []) if FreshConnection::AccessControl.slave_access? change_connection do super(arel, "[#{@model_class.slave_group}] #{name}", binds) end else super end end private def change_connection retry_count = 0 master_connection = @connection begin slave_connection = @model_class.slave_connection @connection = slave_connection.raw_connection yield rescue ActiveRecord::StatementInvalid => exception if @model_class.recovery(slave_connection, exception) retry_count += 1 retry if retry_count < FreshConnection.retry_limit end raise end ensure @connection = master_connection end def configure_connection_with_fresh_connection return if FreshConnection.ignore_configure_connection? configure_connection_without_fresh_connection end end end end
Version data entries
6 entries across 6 versions & 1 rubygems