From 0920c86de3523785b5f4ac67e2090f0736f9fcb2 Mon Sep 17 00:00:00 2001 From: FxQnLr Date: Wed, 28 Feb 2024 19:05:49 +0100 Subject: Closes #18. Added pingthreshold. Cargo update --- src/config.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/config.rs') diff --git a/src/config.rs b/src/config.rs index 4319ffc..58043c2 100644 --- a/src/config.rs +++ b/src/config.rs @@ -7,6 +7,7 @@ pub struct Config { pub apikey: String, pub serveraddr: String, pub pingtimeout: i64, + pub pingthreshold: i64, } impl Config { @@ -14,6 +15,7 @@ impl Config { let config = config::Config::builder() .set_default("serveraddr", "0.0.0.0:7229")? .set_default("pingtimeout", 10)? + .set_default("pingthreshold", 1)? .add_source(File::with_name("config.toml").required(false)) .add_source(File::with_name("config.dev.toml").required(false)) .add_source(config::Environment::with_prefix("WEBOL").prefix_separator("_")) @@ -22,4 +24,3 @@ impl Config { config.try_deserialize() } } - -- cgit v1.2.3 From 85c63c2ca8448428e2db93cb9d4f284a4e314ed7 Mon Sep 17 00:00:00 2001 From: FxQnLr Date: Mon, 4 Mar 2024 21:59:50 +0100 Subject: #20. Set offset manually through config --- src/config.rs | 2 ++ src/main.rs | 11 ++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) (limited to 'src/config.rs') diff --git a/src/config.rs b/src/config.rs index 58043c2..9605361 100644 --- a/src/config.rs +++ b/src/config.rs @@ -8,6 +8,7 @@ pub struct Config { pub serveraddr: String, pub pingtimeout: i64, pub pingthreshold: i64, + pub timeoffset: i8, } impl Config { @@ -16,6 +17,7 @@ impl Config { .set_default("serveraddr", "0.0.0.0:7229")? .set_default("pingtimeout", 10)? .set_default("pingthreshold", 1)? + .set_default("timeoffset", 0)? .add_source(File::with_name("config.toml").required(false)) .add_source(File::with_name("config.dev.toml").required(false)) .add_source(config::Environment::with_prefix("WEBOL").prefix_separator("_")) diff --git a/src/main.rs b/src/main.rs index 8978e58..00fc6ce 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,11 +11,12 @@ use axum::{ }; use dashmap::DashMap; use sqlx::PgPool; +use time::UtcOffset; use std::{env, sync::Arc}; use tokio::sync::broadcast::{channel, Sender}; use tracing::{info, level_filters::LevelFilter}; use tracing_subscriber::{ - fmt::{self, time::UtcTime}, + fmt::{self, time::OffsetTime}, prelude::*, EnvFilter, }; @@ -77,16 +78,18 @@ impl Modify for SecurityAddon { async fn main() -> color_eyre::eyre::Result<()> { color_eyre::install()?; + let config = Config::load()?; + let time_format = time::macros::format_description!("[year]-[month]-[day] [hour]:[minute]:[second]"); - let loc = UtcTime::new(time_format); + let time = OffsetTime::new(UtcOffset::from_hms(config.timeoffset, 0, 0)?, time_format); let file_appender = tracing_appender::rolling::daily("logs", "webol.log"); let (non_blocking, _guard) = tracing_appender::non_blocking(file_appender); tracing_subscriber::registry() .with(fmt::layer().with_writer(non_blocking).with_ansi(false)) - .with(fmt::layer().with_timer(loc)) + .with(fmt::layer().with_timer(time)) .with( EnvFilter::builder() .with_default_directive(LevelFilter::INFO.into()) @@ -96,8 +99,6 @@ async fn main() -> color_eyre::eyre::Result<()> { let version = env!("CARGO_PKG_VERSION"); - let config = Config::load()?; - info!("start webol v{}", version); let db = init_db_pool(&config.database_url).await; -- cgit v1.2.3