Sha256: 163259c78d75a6610570592cba5414b99c6ac68b88013df9499b408b4b97f552
Contents?: true
Size: 1.42 KB
Versions: 1
Compression:
Stored size: 1.42 KB
Contents
class ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter def execute_with_reconnect(sql, name = nil) retryable(sql, name) do |sql_names| retval = nil sql_names.each do |s, n| retval = execute_without_reconnect(s, n) end add_sql_to_transaction(sql, name) retval end end alias_method_chain :execute, :reconnect private def retryable(sql, name, &block) block_with_reconnect = nil sql_names = [[sql, name]] orig_transaction = @transaction Activerecord::Mysql::Reconnect.retryable( :proc => proc { (block_with_reconnect || block).call(sql_names) }, :on_error => proc { unless block_with_reconnect block_with_reconnect = proc do |i| reconnect_without_retry! @transaction = orig_transaction if orig_transaction block.call(i) end end sql_names = merge_transaction(sql, name) }, :sql => sql, :read_only => Activerecord::Mysql::Reconnect.retry_read_only, :connection => @connection ) end def add_sql_to_transaction(sql, name) if (buf = Activerecord::Mysql::Reconnect.retryable_transaction_buffer) buf << [sql, name] end end def merge_transaction(sql, name) sql_name = [sql, name] if (buf = Activerecord::Mysql::Reconnect.retryable_transaction_buffer) buf + [sql_name] else [sql_name] end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
activerecord-mysql-reconnect-0.3.0 | lib/activerecord/mysql/reconnect/abstract_mysql_adapter_ext.rb |