Skip to content
This repository has been archived by the owner on Jul 23, 2021. It is now read-only.

Commit

Permalink
Merge pull request #6 from limebike/nick/negative_one_failover
Browse files Browse the repository at this point in the history
check replica lag nil
  • Loading branch information
njfix6 authored Jun 13, 2019
2 parents 83b6a2c + 902712b commit 74723a2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/distribute_reads.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ def self.lag(connection: nil)
else
status = connection.exec_query("SHOW SLAVE STATUS").to_hash.first
if status
if status["Seconds_Behind_Master"].to_s == 'NULL'
-1.0
if status["Seconds_Behind_Master"].nil?
nil
else
status["Seconds_Behind_Master"].to_f
end
Expand Down
6 changes: 3 additions & 3 deletions lib/distribute_reads/global_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ def distribute_reads(**options)
if max_lag && !options[:primary]
Array(options[:lag_on] || [ActiveRecord::Base]).each do |base_model|
current_lag = DistributeReads.lag(connection: base_model.connection)
if current_lag > max_lag || current_lag == -1.0
if current_lag > max_lag || current_lag.nil?
message = "Replica lag over #{max_lag} seconds#{options[:lag_on] ? " on #{base_model.name} connection" : ""}"
if current_lag == -1.0
message = "Replica lag is -1 on #{base_model.name}"
if current_lag.nil?
message = "Replica lag is nil on #{base_model.name}"
end

if options[:lag_failover]
Expand Down

0 comments on commit 74723a2

Please sign in to comment.