Class: ActiveRecordProxyAdapters::DatabaseConfiguration

Inherits:
Object
  • Object
show all
Includes:
SynchronizableConfiguration
Defined in:
lib/active_record_proxy_adapters/database_configuration.rb

Overview

Provides a global configuration object to configure how the proxy should behave.

Constant Summary collapse

PROXY_DELAY =
2.seconds.freeze
CHECKOUT_TIMEOUT =
2.seconds.freeze
DEFAULT_PREFIX =
proc do |event|
  connection = event.payload[:connection]

  connection.pool.try(:db_config).try(:name) || connection.class::ADAPTER_NAME
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDatabaseConfiguration

Returns a new instance of DatabaseConfiguration.



31
32
33
34
35
36
# File 'lib/active_record_proxy_adapters/database_configuration.rb', line 31

def initialize
  @lock                      = Monitor.new
  self.proxy_delay           = PROXY_DELAY
  self.checkout_timeout      = CHECKOUT_TIMEOUT
  self.log_subscriber_prefix = DEFAULT_PREFIX
end

Instance Attribute Details

#checkout_timeoutActiveSupport::Duration

Returns How long the proxy should wait for a connection from the replica pool. Defaults to CHECKOUT_TIMEOUT. Thread safe.

Returns:

  • (ActiveSupport::Duration)

    How long the proxy should wait for a connection from the replica pool. Defaults to CHECKOUT_TIMEOUT. Thread safe.



26
27
28
# File 'lib/active_record_proxy_adapters/database_configuration.rb', line 26

def checkout_timeout
  @checkout_timeout
end

#log_subscriber_prefixProc

Returns Prefix for the log subscriber when the database is used. Thread safe.

Returns:

  • (Proc)

    Prefix for the log subscriber when the database is used. Thread safe.



29
30
31
# File 'lib/active_record_proxy_adapters/database_configuration.rb', line 29

def log_subscriber_prefix
  @log_subscriber_prefix
end

#proxy_delayActiveSupport::Duration

Returns How long the proxy should reroute all read requests to the primary database since the latest write. Defaults to PROXY_DELAY. Thread safe.

Returns:

  • (ActiveSupport::Duration)

    How long the proxy should reroute all read requests to the primary database since the latest write. Defaults to PROXY_DELAY. Thread safe.



23
24
25
# File 'lib/active_record_proxy_adapters/database_configuration.rb', line 23

def proxy_delay
  @proxy_delay
end