DEV: Add REDIS_RAILS_FAILOVER env to test our new redis failover.

This commit is contained in:
Guo Xiang Tan 2020-06-02 17:24:14 +08:00
parent deb84017f2
commit 439db7ca1e
No known key found for this signature in database
GPG Key ID: FBD110179AAC1F20
5 changed files with 38 additions and 8 deletions

View File

@ -1,6 +1,6 @@
GIT
remote: https://github.com/discourse/rails_failover
revision: 291bf1c18e9a704556a40204d8160549d0438e96
revision: 73ceb21624079e007a7d3bf0bf201f0b34dcd6aa
specs:
rails_failover (0.4.0)
activerecord (~> 6.0)

View File

@ -169,9 +169,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["REDIS_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?
@ -193,9 +199,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["REDIS_RAILS_FAILOVER"]
c[:replica_host] = redis_slave_host
c[:replica_port] = 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

@ -31,6 +31,10 @@ if ENV['ACTIVE_RECORD_RAILS_FAILOVER']
require 'rails_failover/active_record'
end
if ENV['REDIS_RAILS_FAILOVER']
require 'rails_failover/redis'
end
# Global config
require_relative '../app/models/global_setting'
GlobalSetting.configure!

View File

@ -1,5 +1,16 @@
# frozen_string_literal: true
if ENV["REDIS_RAILS_FAILOVER"]
RailsFailover::Redis.on_failover do
Discourse.received_redis_readonly!
end
RailsFailover::Redis.on_fallback do
Discourse.clear_readonly!
Discourse.request_refresh!
end
end
if ENV["ACTIVE_RECORD_RAILS_FAILOVER"]
RailsFailover::ActiveRecord.on_failover do
RailsMultisite::ConnectionManagement.each_connection do

View File

@ -176,7 +176,10 @@ class DiscourseRedis
STDERR.puts "WARN: Redis is in a readonly state. Performed a noop"
end
fallback_handler.verify_master if !fallback_handler.master
if !ENV["REDIS_RAILS_FAILOVER"]
fallback_handler.verify_master if !fallback_handler.master
end
Discourse.received_redis_readonly!
nil
else