DEV: New readonly mode. Only applies to non-staff (#16243)

This commit is contained in:
Daniel Waterworth
2022-05-17 13:06:08 -05:00
committed by GitHub
parent 985afe1092
commit 6e53f4d913
14 changed files with 228 additions and 27 deletions

View File

@ -504,6 +504,9 @@ module Discourse
USER_READONLY_MODE_KEY ||= 'readonly_mode:user'
PG_FORCE_READONLY_MODE_KEY ||= 'readonly_mode:postgres_force'
# Psuedo readonly mode, where staff can still write
STAFF_WRITES_ONLY_MODE_KEY ||= 'readonly_mode:staff_writes_only'
READONLY_KEYS ||= [
READONLY_MODE_KEY,
PG_READONLY_MODE_KEY,
@ -516,7 +519,7 @@ module Discourse
Sidekiq.pause!("pg_failover") if !Sidekiq.paused?
end
if key == USER_READONLY_MODE_KEY || key == PG_FORCE_READONLY_MODE_KEY
if [USER_READONLY_MODE_KEY, PG_FORCE_READONLY_MODE_KEY, STAFF_WRITES_ONLY_MODE_KEY].include?(key)
Discourse.redis.set(key, 1)
else
ttl =
@ -594,6 +597,10 @@ module Discourse
recently_readonly? || Discourse.redis.exists?(*keys)
end
def self.staff_writes_only_mode?
Discourse.redis.get(STAFF_WRITES_ONLY_MODE_KEY).present?
end
def self.pg_readonly_mode?
Discourse.redis.get(PG_READONLY_MODE_KEY).present?
end