ReloadableConfig
A config that can be reloaded while the app runs. Every reload builds the sources again (so files are read again), loads and validates the config, and publishes it to config only if it is valid. A failed reload keeps the last good config and emits the error to failures. Reloads run one at a time, so a slow reload never overwrites a newer one.
val appConfig = ReloadableConfig.load(load = { loadAppConfig() }) {
sources {
+EnvSource()
+TomlSource.fromFile("config.toml")
}
}
scope.launch { appConfig.failures.collect { log.warn("Config reload skipped", it) } }
appConfig.reloadEvery(scope, 30.seconds)
appConfig.config.collect { config -> applyLogLevel(config.logLevel) }Types
Creates a ReloadableConfig with load.
Properties
Errors from reloads that failed and were skipped, see ReloadResult.Failed.error. Nothing is replayed, so start collecting before starting reloads.
Functions
Loads the config again and publishes it if it is valid and different. Never throws except for cancellation: a failure keeps the current config and is emitted to failures.
Reloads each time one of sources reports a change. Pass the same instances that the sources block adds, so the watched source is the one that is read: