DEV: Install `rails_failover` gem to test our Redis changes.

This commit is contained in:
Guo Xiang Tan 2020-05-20 15:40:00 +08:00
parent 30bbc485d0
commit f7f436e536
No known key found for this signature in database
GPG Key ID: FBD110179AAC1F20
4 changed files with 40 additions and 6 deletions

View File

@ -248,3 +248,5 @@ end
gem 'webpush', require: false
gem 'colored2', require: false
gem 'maxminddb'
gem 'rails_failover', require: false

View File

@ -277,6 +277,8 @@ GEM
nokogiri (>= 1.6)
rails-html-sanitizer (1.3.0)
loofah (~> 2.3)
rails_failover (0.1.0)
redis (~> 4)
rails_multisite (2.1.2)
activerecord (> 5.0, < 7)
railties (> 5.0, < 7)
@ -509,6 +511,7 @@ DEPENDENCIES
rack (= 2.2.2)
rack-mini-profiler
rack-protection
rails_failover
rails_multisite
railties (= 6.0.3)
rake

View File

@ -164,9 +164,15 @@ class GlobalSetting
c[:port] = redis_port if redis_port
if redis_slave_host && redis_slave_port
c[:slave_host] = redis_slave_host
c[:slave_port] = redis_slave_port
c[:connector] = DiscourseRedis::Connector
if ENV["RAILS_FAILOVER"]
c[:replica_host] = redis_slave_host
c[:replica_port] = redis_slave_port
c[:connector] = RailsFailover::Redis::Connector
else
c[:slave_host] = redis_slave_host
c[:slave_port] = redis_slave_port
c[:connector] = DiscourseRedis::Connector
end
end
c[:password] = redis_password if redis_password.present?
@ -188,9 +194,15 @@ class GlobalSetting
c[:port] = message_bus_redis_port if message_bus_redis_port
if message_bus_redis_slave_host && message_bus_redis_slave_port
c[:slave_host] = message_bus_redis_slave_host
c[:slave_port] = message_bus_redis_slave_port
c[:connector] = DiscourseRedis::Connector
if ENV["RAILS_FAILOVER"]
c[:replica_host] = message_bus_redis_slave_host
c[:replica_port] = message_bus_redis_slave_port
c[:connector] = RailsFailover::Redis::Connector
else
c[:slave_host] = message_bus_redis_slave_host
c[:slave_port] = message_bus_redis_slave_port
c[:connector] = DiscourseRedis::Connector
end
end
c[:password] = message_bus_redis_password if message_bus_redis_password.present?

View File

@ -4,3 +4,20 @@ if Rails.env.development? && ENV['DISCOURSE_FLUSH_REDIS']
puts "Flushing redis (development mode)"
Discourse.redis.flushdb
end
if ENV['RAILS_FAILOVER']
require 'rails_failover'
message_bus_keepalive_interval = MessageBus.keepalive_interval
RailsFailover::Redis.register_master_up_callback do
MessageBus.keepalive_interval = message_bus_keepalive_interval
Discourse.clear_readonly!
Discourse.request_refresh!
end
RailsFailover::Redis.register_master_down_callback do
# Disables MessageBus keepalive when Redis is in readonly mode
MessageBus.keepalive_interval = 0
end
end