Class: PgFailover::ConnectionValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/pg_failover/connection_validator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ ConnectionValidator

Returns a new instance of ConnectionValidator.



5
6
7
8
9
10
# File 'lib/pg_failover/connection_validator.rb', line 5

def initialize(config)
  @logger = config.logger
  @max_retries = config.max_retries
  @throttle = Throttle.new(throttle_interval: config.throttle_interval)
  @config = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



12
13
14
# File 'lib/pg_failover/connection_validator.rb', line 12

def config
  @config
end

#loggerObject (readonly)

Returns the value of attribute logger.



12
13
14
# File 'lib/pg_failover/connection_validator.rb', line 12

def logger
  @logger
end

#max_retriesObject (readonly)

Returns the value of attribute max_retries.



12
13
14
# File 'lib/pg_failover/connection_validator.rb', line 12

def max_retries
  @max_retries
end

#throttleObject (readonly)

Returns the value of attribute throttle.



12
13
14
# File 'lib/pg_failover/connection_validator.rb', line 12

def throttle
  @throttle
end

#throttle_intervalObject (readonly)

Returns the value of attribute throttle_interval.



12
13
14
# File 'lib/pg_failover/connection_validator.rb', line 12

def throttle_interval
  @throttle_interval
end

Instance Method Details

#call(in_recovery:, reconnect:, throttle_by:) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/pg_failover/connection_validator.rb', line 14

def call(in_recovery:, reconnect:, throttle_by:)
  if config.throttle_enabled?
    throttle.on_stale(throttle_by) { check_and_reconnect(in_recovery, reconnect) }
  else
    check_and_reconnect(in_recovery, reconnect)
  end
end