2021-11-03 17:34:42 +00:00
|
|
|
class GlobalConfigService
|
|
|
|
def self.load(config_key, default_value)
|
2022-07-15 02:51:59 +00:00
|
|
|
config = ENV.fetch(config_key) { GlobalConfig.get(config_key)[config_key] }
|
2022-01-12 03:20:23 +00:00
|
|
|
return config if config.present?
|
2021-11-03 17:34:42 +00:00
|
|
|
|
|
|
|
# To support migrating existing instance relying on env variables
|
|
|
|
# TODO: deprecate this later down the line
|
2022-07-15 02:51:59 +00:00
|
|
|
config_value = ENV.fetch(config_key) { default_value }
|
2021-11-03 17:34:42 +00:00
|
|
|
|
|
|
|
return if config_value.blank?
|
|
|
|
|
2021-11-11 14:01:25 +00:00
|
|
|
i = InstallationConfig.where(name: config_key).first_or_create(value: config_value, locked: false)
|
2021-11-03 17:34:42 +00:00
|
|
|
# To clear a nil value that might have been cached in the previous call
|
|
|
|
GlobalConfig.clear_cache
|
|
|
|
i.value
|
|
|
|
end
|
|
|
|
end
|