module ActiveRecord::AllowConnectionFailure

Constants

VERSION

Public Class Methods

complete(state) click to toggle source
# File lib/active_record/allow_connection_failure.rb, line 20
def self.complete(state)
  if ActiveRecord::Base.connected?
    enabled, connection_id = state

    ActiveRecord::Base.connection_id = connection_id
    ActiveRecord::Base.connection.clear_query_cache
    ActiveRecord::Base.connection.disable_query_cache! unless enabled
  end
end
install_executor_hooks(executor = ActiveSupport::Executor) click to toggle source
# File lib/active_record/allow_connection_failure.rb, line 30
def self.install_executor_hooks(executor = ActiveSupport::Executor)
  executor.register_hook(self)

  executor.to_complete do
    unless ActiveRecord::Base.connected? && ActiveRecord::Base.connection.transaction_open?
      ActiveRecord::Base.clear_active_connections!
    end
  end
end
run() click to toggle source
# File lib/active_record/allow_connection_failure.rb, line 9
def self.run
  if ActiveRecord::Base.connected?
    connection    = ActiveRecord::Base.connection
    enabled       = connection.query_cache_enabled
    connection_id = ActiveRecord::Base.connection_id
    connection.enable_query_cache!

    [enabled, connection_id]
  end
end

Public Instance Methods

call(env) click to toggle source
# File lib/active_record/allow_connection_failure.rb, line 43
def call(env)
  if ActiveRecord::Base.connected? && connection.supports_migrations?
    mtime = ActiveRecord::Migrator.last_migration.mtime.to_i
    if @last_check < mtime
      ActiveRecord::Migration.check_pending!(connection)
      @last_check = mtime
    end
  end
  @app.call(env)
end