Fix rake mastodon:setup Redis configuration loading

Alternative to #22053
This commit is contained in:
Claire 2024-10-03 16:07:36 +02:00
parent f768a6eb16
commit f4c0f3940a
2 changed files with 12 additions and 8 deletions

View File

@ -7,6 +7,13 @@ class Mastodon::RedisConfiguration
db: 0, db: 0,
}.freeze }.freeze
def reset!
@base = nil
@sidekiq = nil
@cache = nil
@namespace = nil
end
def base def base
@base ||= setup_config(prefix: nil, defaults: DEFAULTS) @base ||= setup_config(prefix: nil, defaults: DEFAULTS)
.merge(namespace: base_namespace) .merge(namespace: base_namespace)

View File

@ -8,14 +8,6 @@ namespace :mastodon do
prompt = TTY::Prompt.new prompt = TTY::Prompt.new
env = {} env = {}
# When the application code gets loaded, it runs `lib/mastodon/redis_configuration.rb`.
# This happens before application environment configuration and sets REDIS_URL etc.
# These variables are then used even when REDIS_HOST etc. are changed, so clear them
# out so they don't interfere with our new configuration.
ENV.delete('REDIS_URL')
ENV.delete('CACHE_REDIS_URL')
ENV.delete('SIDEKIQ_REDIS_URL')
begin begin
errors = false errors = false
@ -533,6 +525,11 @@ namespace :mastodon do
ENV[key] = value.to_s ENV[key] = value.to_s
end end
# Redis configuration happens very early when the application code is loaded.
# This happens before the `mastodon:setup` task runs, so we have to refresh it with
# the new environment variable values.
REDIS_CONFIGURATION.reset!
require_relative '../../config/environment' require_relative '../../config/environment'
disable_log_stdout! disable_log_stdout!