mirror of
https://github.com/discourse/discourse.git
synced 2025-03-25 23:35:43 +08:00
DEV: Allow multisite apps to boot with readonly db.
This commit is contained in:
parent
27b2e335ef
commit
84c12d8f3d
@ -6,6 +6,22 @@ module RailsMultisite
|
|||||||
self.each_connection do |db|
|
self.each_connection do |db|
|
||||||
begin
|
begin
|
||||||
yield(db) if block_given?
|
yield(db) if block_given?
|
||||||
|
rescue PG::ConnectionBad, PG::UnableToSend, PG::ServerError
|
||||||
|
break if !defined?(RailsFailover::ActiveRecord)
|
||||||
|
break if db == RailsMultisite::ConnectionManagement::DEFAULT
|
||||||
|
|
||||||
|
reading_role = :"#{db}_#{ActiveRecord::Base.reading_role}"
|
||||||
|
spec = RailsMultisite::ConnectionManagement.connection_spec(db: db)
|
||||||
|
|
||||||
|
ActiveRecord::Base.connection_handlers[reading_role] ||= begin
|
||||||
|
handler = ActiveRecord::ConnectionAdapters::ConnectionHandler.new
|
||||||
|
RailsFailover::ActiveRecord.establish_reading_connection(handler, spec)
|
||||||
|
handler
|
||||||
|
end
|
||||||
|
|
||||||
|
ActiveRecord::Base.connected_to(role: reading_role) do
|
||||||
|
yield(db) if block_given?
|
||||||
|
end
|
||||||
rescue => e
|
rescue => e
|
||||||
STDERR.puts "URGENT: Failed to initialize site #{db}: "\
|
STDERR.puts "URGENT: Failed to initialize site #{db}: "\
|
||||||
"#{e.class} #{e.message}\n#{e.backtrace.join("\n")}"
|
"#{e.class} #{e.message}\n#{e.backtrace.join("\n")}"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user