FIX: PostgreSQLFallbackHandler was bouncing in and out of readonly.

This commit is contained in:
Guo Xiang Tan
2016-03-08 09:37:40 +08:00
parent 74e4251aff
commit fcc86d3a9d
2 changed files with 20 additions and 6 deletions

View File

@ -39,7 +39,7 @@ class PostgreSQLFallbackHandler
end
Discourse.disable_readonly_mode
master = true
self.master = true
end
rescue => e
if e.message.include?("could not connect to server")
@ -77,6 +77,10 @@ class PostgreSQLFallbackHandler
end
end
def verify?
!master && !running && !recently_checked?
end
private
def config
@ -110,7 +114,7 @@ module ActiveRecord
fallback_handler = ::PostgreSQLFallbackHandler.instance
config = config.symbolize_keys
if !fallback_handler.master && !fallback_handler.running
if fallback_handler.verify?
connection = postgresql_connection(config.dup.merge({
host: config[:replica_host], port: config[:replica_port]
}))
@ -148,9 +152,7 @@ module ActiveRecord
end
def switch_back?
if !fallback_handler.master && !fallback_handler.running
fallback_handler.verify_master
end
fallback_handler.verify_master if fallback_handler.verify?
end
end
end