Module: AdvancedConnection::ActiveRecordExt::ConnectionPool::WithoutConnection

Extended by:
ActiveSupport::Concern
Defined in:
lib/advanced_connection/active_record_ext/connection_pool/without_connection.rb

Constant Summary collapse

MAX_REAQUIRE_ATTEMPTS =
3

Instance Method Summary collapse

Instance Method Details

#without_connection(&block) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/advanced_connection/active_record_ext/connection_pool/without_connection.rb', line 39

def without_connection(&block)
  return unless block_given?

  # if we're not enabled just execute the block and return
  return block.call unless AdvancedConnection.enable_without_connection

  # if we have a transaction open, we can't release the database connection
  # or Bad Things (tm) happen - so we just execute our block and return
  if transaction_open?
    Rails.logger.warn "WithoutConnection skipped due to open transaction."
    return block.call
  end

  if AdvancedConnection.callbacks.without_connection.present?
    run_callbacks(:without_connection) do
      __without_connection { block.call }
    end
  else
    __without_connection { block.call }
  end
end