DEV: Rescue errors when runngin AR failover/fallback callbacks.
This commit is contained in:
parent
34ee1f2e71
commit
1411b095eb
|
@ -29,6 +29,9 @@ if ENV["ACTIVE_RECORD_RAILS_FAILOVER"]
|
||||||
Discourse.enable_readonly_mode(Discourse::PG_READONLY_MODE_KEY)
|
Discourse.enable_readonly_mode(Discourse::PG_READONLY_MODE_KEY)
|
||||||
Sidekiq.pause!("pg_failover") if !Sidekiq.paused?
|
Sidekiq.pause!("pg_failover") if !Sidekiq.paused?
|
||||||
end
|
end
|
||||||
|
rescue => e
|
||||||
|
Discourse.warn_exception(e, message: "Failed to run failover callback")
|
||||||
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
RailsFailover::ActiveRecord.on_fallback do
|
RailsFailover::ActiveRecord.on_fallback do
|
||||||
|
@ -41,6 +44,9 @@ if ENV["ACTIVE_RECORD_RAILS_FAILOVER"]
|
||||||
RailsMultisite::ConnectionManagement.default_connection_handler =
|
RailsMultisite::ConnectionManagement.default_connection_handler =
|
||||||
ActiveRecord::Base.connection_handlers[ActiveRecord::Base.writing_role]
|
ActiveRecord::Base.connection_handlers[ActiveRecord::Base.writing_role]
|
||||||
end
|
end
|
||||||
|
rescue => e
|
||||||
|
Discourse.warn_exception(e, message: "Failed to run fallback callback")
|
||||||
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
module Discourse
|
module Discourse
|
||||||
|
@ -65,14 +71,12 @@ if ENV["ACTIVE_RECORD_RAILS_FAILOVER"]
|
||||||
end
|
end
|
||||||
|
|
||||||
RailsFailover::ActiveRecord.register_force_reading_role_callback do
|
RailsFailover::ActiveRecord.register_force_reading_role_callback do
|
||||||
begin
|
Discourse.redis.exists(
|
||||||
Discourse.redis.exists(
|
Discourse::PG_READONLY_MODE_KEY,
|
||||||
Discourse::PG_READONLY_MODE_KEY,
|
Discourse::PG_FORCE_READONLY_MODE_KEY
|
||||||
Discourse::PG_FORCE_READONLY_MODE_KEY
|
)
|
||||||
)
|
rescue => e
|
||||||
rescue => e
|
Discourse.warn_exception(e, message: "Failed to force AR reading role")
|
||||||
Discourse.warn_exception(e, message: "Failed to force AR reading role")
|
false
|
||||||
false
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue