Skip to content

Commit

Permalink
docs: documented startup mode
Browse files Browse the repository at this point in the history
  • Loading branch information
raphael-goetz committed Dec 26, 2024
1 parent 226ec97 commit c993051
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
30 changes: 18 additions & 12 deletions aquila/src/configuration/config.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::configuration::environment::Environment;
use crate::configuration::mode::Mode;
use dotenv::from_filename;
use log::{error, info};
use std::env;
use std::fmt::{Debug, Display};
use std::str::FromStr;
use dotenv::from_filename;
use log::{error, info};
use crate::configuration::environment::Environment;
use crate::configuration::mode::Mode;

/// Struct for all relevant `Aquila` startup configurations
pub struct Config {
Expand All @@ -15,7 +15,13 @@ pub struct Config {
/// `staging`
/// `production`
pub environment: Environment,


/// Aquila mode
///
/// Options:
/// `static` (default)
/// `hybrid`
/// `dynamic`
pub mode: Mode,

/// URL to the Redis Server.
Expand Down Expand Up @@ -54,7 +60,10 @@ impl Config {
mode: Self::get_mode("MODE", Mode::STATIC),
redis_url: Self::get_string("REDIS_URL", "redis://redis:6379"),
update_schedule_interval: Self::get_u32("UPDATE_SCHEDULE_INTERVAL", 3600),
flow_fallback_path: Self::get_string("FLOW_FALLBACK_PATH", "configuration/configuration.json"),
flow_fallback_path: Self::get_string(
"FLOW_FALLBACK_PATH",
"configuration/configuration.json",
),
session_token: Self::get_string("SESSION_TOKEN", "default_session_token"),
backend_url: Self::get_string("BACKEND_URL", "http://localhost:8080"),
}
Expand All @@ -74,7 +83,7 @@ impl Config {

Environment::from_str(&value)
}

fn get_mode(key: &str, default: Mode) -> Mode {
let value = match env::var(key) {
Ok(result) => {
Expand All @@ -86,17 +95,14 @@ impl Config {
return default;
}
};

Mode::from_str(&value)
}

fn get_string(key: &str, default: &str) -> String {
Self::get_env_with_default(key, String::from(default))
}

fn get_bool(key: &str, default: bool) -> bool {
Self::get_env_with_default(key, default)
}
fn get_u32(key: &str, default: u32) -> u32 {
Self::get_env_with_default(key, default)
}
Expand Down Expand Up @@ -132,4 +138,4 @@ impl Config {
info!("Env. variable {} was set to the value: {:?}", name, result);
result
}
}
}
10 changes: 10 additions & 0 deletions aquila/src/configuration/mode.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/// Aquila Startup-Mode
///
/// STATIC:
/// Aquila will start from configuration file
///
/// DYNAMIC:
/// Aquila will be updated by releases (via request scheduler)
///
/// HYBRID
/// Aquila will be updated by updates (via stream)
pub enum Mode {
STATIC,
DYNAMIC,
Expand Down

0 comments on commit c993051

Please sign in to comment.