DEV: Make rails_failover compatible with `SKIP_DB_AND_REDIS` env.

This commit is contained in:
Guo Xiang Tan 2020-06-15 16:23:24 +08:00
parent e0d798c06c
commit 402b80f306
No known key found for this signature in database
GPG Key ID: FBD110179AAC1F20
3 changed files with 8 additions and 5 deletions

View File

@ -163,7 +163,7 @@ class GlobalSetting
c[:host] = redis_host if redis_host
c[:port] = redis_port if redis_port
if redis_slave_host && redis_slave_port
if redis_slave_host && redis_slave_port && defined?(RailsFailover)
c[:replica_host] = redis_slave_host
c[:replica_port] = redis_slave_port
c[:connector] = RailsFailover::Redis::Connector

View File

@ -1,6 +1,6 @@
# frozen_string_literal: true
if !GlobalSetting.skip_redis?
if defined?(RailsFailover::Redis)
message_bus_keepalive_interval = nil
RailsFailover::Redis.on_failover do
@ -16,7 +16,7 @@ if !GlobalSetting.skip_redis?
end
end
if !GlobalSetting.skip_db?
if defined?(RailsFailover::ActiveRecord)
if Rails.configuration.multisite
if ActiveRecord::Base.current_role == ActiveRecord::Base.reading_role
RailsMultisite::ConnectionManagement.default_connection_handler =

View File

@ -24,7 +24,10 @@ if Rails.configuration.multisite
# Multisite needs to be first, because the request tracker and message bus rely on it
Rails.configuration.middleware.unshift RailsMultisite::Middleware, RailsMultisite::DiscoursePatches.config
Rails.configuration.middleware.delete ActionDispatch::Executor
Rails.configuration.middleware.insert_after(RailsMultisite::Middleware, RailsFailover::ActiveRecord::Middleware)
else
if defined?(RailsFailover)
Rails.configuration.middleware.insert_after(RailsMultisite::Middleware, RailsFailover::ActiveRecord::Middleware)
end
elsif defined?(RailsFailover)
Rails.configuration.middleware.insert_before(MessageBus::Rack::Middleware, RailsFailover::ActiveRecord::Middleware)
end