diff --git a/config.toml b/config.toml index cb364be..8e8f96e 100644 --- a/config.toml +++ b/config.toml @@ -1,4 +1,4 @@ [config] database_path = "src/storage/db.sqlite" max_workers = 100 -min_workers = 0 \ No newline at end of file +min_workers = 200 \ No newline at end of file diff --git a/src/config.rs b/src/config.rs index 72aba59..317cb14 100644 --- a/src/config.rs +++ b/src/config.rs @@ -54,8 +54,8 @@ pub struct CLIArguments { /// Path to the config file #[arg(default_value = "config.toml")] config: PathBuf, - /// Maximum amount of workers to use - /// If not set, the max is calculated depending on system resources + /// Maximum amount of workers to use. + /// If not set, the max is calculated depending on system resources. /// A value of 0 will cause the server to be singlethreaded, potentially reducing the performance and responsiveness by a lot #[arg(long)] max_workers: Option, @@ -90,7 +90,9 @@ pub fn read_from_env() -> Result { Ok(d) => d, Err(err) => bail!("Failed to parse config file. Error: {err}"), }; - Ok(unsanitized.into_config(&args)) + let conf = unsanitized.into_config(&args); + conf.sanity_check()?; + Ok(conf) } fn calc_max_workers_from_system() -> u32 { @@ -161,3 +163,12 @@ impl ConfigRootToml { } } } + +impl Config { + fn sanity_check(&self) -> Result<(), Error> { + if self.min_workers > self.max_workers { + bail!("Minimum amount of workers ({}) can't be greater than maximum amount of workers ({})", self.min_workers, self.max_workers) + }; + Ok(()) + } +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 97e081f..20e1ba0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,5 +17,5 @@ mod webui; fn main() { - println!("{:?}", config::read_from_env()); + storage::establish_connection("./src/storage/db.sqlite"); } \ No newline at end of file diff --git a/src/storage/mod.rs b/src/storage/mod.rs index dd457b6..ff747be 100644 --- a/src/storage/mod.rs +++ b/src/storage/mod.rs @@ -8,24 +8,21 @@ // See the Licence for the specific language governing permissions and limitations under the Licence. // -use diesel::{prelude::*, sqlite::Sqlite}; -use diesel::pg::PgConnection; +use diesel::{prelude::*, pg::PgConnection, sqlite::Sqlite}; use diesel_migrations::{EmbeddedMigrations, embed_migrations, MigrationHarness}; -use dotenvy::dotenv; -use std::{env, error::Error}; +use std::error::Error; pub const MIGRATIONS: EmbeddedMigrations = embed_migrations!("migrations"); pub fn establish_connection(db_url: &str) -> PgConnection { - dotenv().ok(); + //SqliteConnection::establish(db_url).unwrap_or_else(|e| panic!("Error connecting to {}: {}", db_url, e)) let conn = PgConnection::establish(db_url) - .unwrap_or_else(|_| panic!("Error connecting to {}", db_url)); + .unwrap_or_else(|e| panic!("Error connecting to {}: {}", db_url, e)); // TODO: Add migrations here conn } - fn run_migrations_sqlite(connection: &mut impl MigrationHarness) -> Result<(), Box> { // This will run the necessary migrations.