DEV: Rescue errors when runngin AR failover/fallback callbacks.

This commit is contained in:
Guo Xiang Tan 2020-06-11 13:02:19 +08:00
parent 34ee1f2e71
commit 1411b095eb
No known key found for this signature in database
GPG Key ID: FBD110179AAC1F20
1 changed files with 13 additions and 9 deletions

View File

@ -29,6 +29,9 @@ if ENV["ACTIVE_RECORD_RAILS_FAILOVER"]
Discourse.enable_readonly_mode(Discourse::PG_READONLY_MODE_KEY)
Sidekiq.pause!("pg_failover") if !Sidekiq.paused?
end
rescue => e
Discourse.warn_exception(e, message: "Failed to run failover callback")
false
end
RailsFailover::ActiveRecord.on_fallback do
@ -41,6 +44,9 @@ if ENV["ACTIVE_RECORD_RAILS_FAILOVER"]
RailsMultisite::ConnectionManagement.default_connection_handler =
ActiveRecord::Base.connection_handlers[ActiveRecord::Base.writing_role]
end
rescue => e
Discourse.warn_exception(e, message: "Failed to run fallback callback")
false
end
module Discourse
@ -65,14 +71,12 @@ if ENV["ACTIVE_RECORD_RAILS_FAILOVER"]
end
RailsFailover::ActiveRecord.register_force_reading_role_callback do
begin
Discourse.redis.exists(
Discourse::PG_READONLY_MODE_KEY,
Discourse::PG_FORCE_READONLY_MODE_KEY
)
rescue => e
Discourse.warn_exception(e, message: "Failed to force AR reading role")
false
end
Discourse.redis.exists(
Discourse::PG_READONLY_MODE_KEY,
Discourse::PG_FORCE_READONLY_MODE_KEY
)
rescue => e
Discourse.warn_exception(e, message: "Failed to force AR reading role")
false
end
end