Sha256: 4f53c7a9d162324503ab3b802b7a4032a763e0c81fed26c414bd4e6c5ba3f2e3

Contents?: true

Size: 1.12 KB

Versions: 6

Compression:

Stored size: 1.12 KB

Contents

module Activerecord::Mysql::Reconnect::ExecuteWithReconnect
  def execute(sql, name = nil)
    retryable(sql, name) do |sql_names|
      retval = nil

      sql_names.each do |s, n|
        retval = super(s, n)
      end

      retval
    end
  end
end

class ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter
  prepend Activerecord::Mysql::Reconnect::ExecuteWithReconnect

  private

  def retryable(sql, name, &block)
    block_with_reconnect = nil
    sql_names = [[sql, name]]
    transaction = current_transaction

    if sql =~ /\ABEGIN\z/i and transaction.is_a?(ActiveRecord::ConnectionAdapters::NullTransaction)
      def transaction.state; nil; end
    end

    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!
            block.call(i)
          end
        end
      },
      :sql => sql,
      :retry_mode => Activerecord::Mysql::Reconnect.retry_mode,
      :connection => @connection
    )
  end
end

Version data entries

6 entries across 6 versions & 3 rubygems

Version Path
activerecord-mysql-reconnect-new-0.6.0 lib/activerecord/mysql/reconnect/abstract_mysql_adapter_ext.rb
activerecord-mysql-reconnect-before-retry-0.5.0 lib/activerecord/mysql/reconnect/abstract_mysql_adapter_ext.rb
activerecord-mysql-reconnect-0.5.0 lib/activerecord/mysql/reconnect/abstract_mysql_adapter_ext.rb
activerecord-mysql-reconnect-0.4.2 lib/activerecord/mysql/reconnect/abstract_mysql_adapter_ext.rb
activerecord-mysql-reconnect-0.4.1 lib/activerecord/mysql/reconnect/abstract_mysql_adapter_ext.rb
activerecord-mysql-reconnect-0.4.1.beta lib/activerecord/mysql/reconnect/abstract_mysql_adapter_ext.rb