DEV: Enable readonly mode for all multisite sites when PG goes down.

The risk here is that the database for one site goes down in the multisite setup and we drop everything to readonly mode. However, I discussed this with Sam and we agree that one database having problem is very rare. Most of the time, it is the entire DB cluster that goes down.
This commit is contained in:
Guo Xiang Tan 2020-06-02 11:32:07 +08:00
parent 7897010dfd
commit ade60b0cbc
No known key found for this signature in database
GPG Key ID: FBD110179AAC1F20
1 changed files with 8 additions and 2 deletions

View File

@ -2,12 +2,18 @@
if ENV["ACTIVE_RECORD_RAILS_FAILOVER"]
RailsFailover::ActiveRecord.on_failover do
Discourse.enable_readonly_mode(Discourse::PG_READONLY_MODE_KEY)
RailsMultisite::ConnectionManagement.each_connection do
Discourse.enable_readonly_mode(Discourse::PG_READONLY_MODE_KEY)
end
Sidekiq.pause!("pg_failover") if !Sidekiq.paused?
end
RailsFailover::ActiveRecord.on_fallback do
Discourse.disable_readonly_mode(Discourse::PG_READONLY_MODE_KEY)
RailsMultisite::ConnectionManagement.each_connection do
Discourse.disable_readonly_mode(Discourse::PG_READONLY_MODE_KEY)
end
Sidekiq.unpause!
end