feat: add GlobalConfigService to support env vars migration (#3288)

This commit is contained in:
Vishnu Narayanan
2021-11-03 23:04:42 +05:30
committed by GitHub
parent 03b1a3d045
commit 97ee1bfa97
7 changed files with 104 additions and 39 deletions

View File

@@ -15,6 +15,10 @@ class GlobalConfig
config.with_indifferent_access
end
def get_value(arg)
load_from_cache(arg)
end
def clear_cache
cached_keys = $alfred.keys("#{VERSION}:#{KEY_PREFIX}:*")
(cached_keys || []).each do |cached_key|

View File

@@ -0,0 +1,17 @@
class GlobalConfigService
def self.load(config_key, default_value)
config = GlobalConfig.get(config_key)
return config[config_key] if config[config_key].present?
# To support migrating existing instance relying on env variables
# TODO: deprecate this later down the line
config_value = ENV[config_key] || default_value
return if config_value.blank?
i = InstallationConfig.where(name: config_key).first_or_create(value: config_value)
# To clear a nil value that might have been cached in the previous call
GlobalConfig.clear_cache
i.value
end
end