DEV: Don't configure rails_failover is db and redis is skipped.

DEV: Don’t configure rails_failover is db and redis is skipped.

diff --git a/config/application.rb b/config/application.rb
index 0e17596..1b0db35 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -19,8 +19,14 @@ require 'action_controller/railtie'
 require 'action_view/railtie'
 require 'action_mailer/railtie'
 require 'sprockets/railtie'
-require 'rails_failover/active_record'
-require 'rails_failover/redis'
+
+if !GlobalSetting.skip_db
+  require 'rails_failover/active_record'
+end
+
+if !GlobalSetting.skip_redis
+  require 'rails_failover/redis'
+end
 
 # Plugin related stuff
 require_relative '../lib/plugin_initialization_guard'
diff --git a/config/initializers/002-rails_failover.rb b/config/initializers/002-rails_failover.rb
index 1c0edc9..d60c1c1 100644
--- a/config/initializers/002-rails_failover.rb
+++ b/config/initializers/002-rails_failover.rb
@@ -1,51 +1,55 @@
 # frozen_string_literal: true
 
-message_bus_keepalive_interval = nil
+if !GlobalSetting.skip_redis
+  message_bus_keepalive_interval = nil
 
-RailsFailover::Redis.on_failover do
-  message_bus_keepalive_interval = MessageBus.keepalive_interval
-  MessageBus.keepalive_interval = -1 # Disable MessageBus keepalive_interval
-  Discourse.received_redis_readonly!
-end
-
-RailsFailover::Redis.on_fallback do
-  Discourse.clear_redis_readonly!
-  Discourse.request_refresh!
-  MessageBus.keepalive_interval = message_bus_keepalive_interval
-end
+  RailsFailover::Redis.on_failover do
+    message_bus_keepalive_interval = MessageBus.keepalive_interval
+    MessageBus.keepalive_interval = -1 # Disable MessageBus keepalive_interval
+    Discourse.received_redis_readonly!
+  end
 
-if Rails.configuration.multisite
-  if ActiveRecord::Base.current_role == ActiveRecord::Base.reading_role
-    RailsMultisite::ConnectionManagement.default_connection_handler =
-      ActiveRecord::Base.connection_handlers[ActiveRecord::Base.reading_role]
+  RailsFailover::Redis.on_fallback do
+    Discourse.clear_redis_readonly!
+    Discourse.request_refresh!
+    MessageBus.keepalive_interval = message_bus_keepalive_interval
   end
 end
 
-RailsFailover::ActiveRecord.on_failover do
-  RailsMultisite::ConnectionManagement.each_connection do
-    Discourse.enable_readonly_mode(Discourse::PG_READONLY_MODE_KEY)
-    Sidekiq.pause!("pg_failover") if !Sidekiq.paused?
+if !GlobalSetting.skip_db
+  if Rails.configuration.multisite
+    if ActiveRecord::Base.current_role == ActiveRecord::Base.reading_role
+      RailsMultisite::ConnectionManagement.default_connection_handler =
+        ActiveRecord::Base.connection_handlers[ActiveRecord::Base.reading_role]
+    end
   end
-end
 
-RailsFailover::ActiveRecord.on_fallback do
-  RailsMultisite::ConnectionManagement.each_connection do
-    Discourse.disable_readonly_mode(Discourse::PG_READONLY_MODE_KEY)
-    Sidekiq.unpause! if Sidekiq.paused?
+  RailsFailover::ActiveRecord.on_failover do
+    RailsMultisite::ConnectionManagement.each_connection do
+      Discourse.enable_readonly_mode(Discourse::PG_READONLY_MODE_KEY)
+      Sidekiq.pause!("pg_failover") if !Sidekiq.paused?
+    end
   end
 
-  if Rails.configuration.multisite
-    RailsMultisite::ConnectionManagement.default_connection_handler =
-      ActiveRecord::Base.connection_handlers[ActiveRecord::Base.writing_role]
+  RailsFailover::ActiveRecord.on_fallback do
+    RailsMultisite::ConnectionManagement.each_connection do
+      Discourse.disable_readonly_mode(Discourse::PG_READONLY_MODE_KEY)
+      Sidekiq.unpause! if Sidekiq.paused?
+    end
+
+    if Rails.configuration.multisite
+      RailsMultisite::ConnectionManagement.default_connection_handler =
+        ActiveRecord::Base.connection_handlers[ActiveRecord::Base.writing_role]
+    end
   end
-end
 
-RailsFailover::ActiveRecord.register_force_reading_role_callback do
-  Discourse.redis.exists?(
-    Discourse::PG_READONLY_MODE_KEY,
-    Discourse::PG_FORCE_READONLY_MODE_KEY
-  )
-rescue => e
-  Rails.logger.warn "#{e.class} #{e.message}: #{e.backtrace.join("\n")}"
-  false
+  RailsFailover::ActiveRecord.register_force_reading_role_callback do
+    Discourse.redis.exists?(
+      Discourse::PG_READONLY_MODE_KEY,
+      Discourse::PG_FORCE_READONLY_MODE_KEY
+    )
+  rescue => e
+    Rails.logger.warn "#{e.class} #{e.message}: #{e.backtrace.join("\n")}"
+    false
+  end
 end

GitHub sha: e0fdf415