Module apollo_framework::config [−][src]
Expand description
Contains the system configuration.
Provides access to the system configuration which is loaded from the config/settings.yml file. Note that we observe this file for changes and reload it once a change is detected. Therefore each user of the config should attach itself to the Config::notifier and re-process the config once a change message is received.
Being an in-memory database framework we want to prevent restarts / downtimes as much as possible.
Note that the Config struct is kind of constant and can be obtained from the Platform once and then kept around. However, when using Config::current() to obtain the current config handle, this should not be stored, as it will not be updated once a new config has been loaded.
Examples
Obtaining and reading the config:
// Create a platform and install the config...
let platform = Platform::new();
let config = config::install(platform.clone(), false).await;
// Fetch the current config document (might be reloaded from time to time) and read the
// selected server port..
let port = config.current().config()["server"]["port"].as_i64().unwrap_or(1234);
Attaching a change listener:
// Create a platform and install the config...
let platform = Platform::new();
let config = config::install(platform.clone(), false);
// Obtain the config...
let config = platform.require::<Config>();
tokio::spawn(async move {
loop {
// Wait for a config change. This will most probably be combined with a read from
// a command queue or another feature using tokio::select!...
match config.notifier().recv().await {
Ok(_) => log::info!("Config update received..."),
_ => return,
}
}
});
Structs
Provides access to the system configuration.
Represents a handle to the currently loaded configuration.
Functions
Creates an installs a Config for the given platform.
Type Definitions
Represents the change listener.