From da61ce2436a8a561779d0b80901ebac139b2d016 Mon Sep 17 00:00:00 2001 From: arkanoider <113362043+arkanoider@users.noreply.github.com> Date: Wed, 1 Nov 2023 18:36:07 +0100 Subject: [PATCH] added configurable interval for user rate send events (#134) --- settings.tpl.toml | 2 ++ src/cli/settings.rs | 1 + src/scheduler.rs | 8 ++++++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/settings.tpl.toml b/settings.tpl.toml index 4da8931..392c070 100644 --- a/settings.tpl.toml +++ b/settings.tpl.toml @@ -29,6 +29,8 @@ min_payment_amount = 100 expiration_hours = 24 # Expiration of pending orders expiration_seconds = 900 +# User rate events scheduled time interval +user_rates_sent_interval_seconds = 3600 [database] url = "sqlite://mostro.db" diff --git a/src/cli/settings.rs b/src/cli/settings.rs index 641fd93..46d9772 100644 --- a/src/cli/settings.rs +++ b/src/cli/settings.rs @@ -97,6 +97,7 @@ pub struct Mostro { pub min_payment_amount: u32, pub expiration_hours: u32, pub expiration_seconds: u32, + pub user_rates_sent_interval_seconds: u32, } impl TryFrom for Mostro { diff --git a/src/scheduler.rs b/src/scheduler.rs index 5b4550f..84dae96 100644 --- a/src/scheduler.rs +++ b/src/scheduler.rs @@ -23,6 +23,8 @@ pub async fn start_scheduler(rate_list: Arc>>, client: &Client) async fn job_update_rate_events(client: Client, rate_list: Arc>>) { // Clone for closure owning with Arc let inner_list = rate_list.clone(); + let mostro_settings = Settings::get_mostro(); + let user_rates_sent_seconds = mostro_settings.user_rates_sent_interval_seconds as u64; tokio::spawn(async move { loop { @@ -44,13 +46,15 @@ async fn job_update_rate_events(client: Client, rate_list: Arc> inner_list.lock().await.clear(); let now = Utc::now(); - let next_tick = now.checked_add_signed(Duration::hours(1)).unwrap(); + let next_tick = now + .checked_add_signed(Duration::seconds(user_rates_sent_seconds as i64)) + .unwrap(); info!( "Next tick for update users rating is {}", next_tick.format("%a %b %e %T %Y") ); - tokio::time::sleep(tokio::time::Duration::from_secs(3600)).await; + tokio::time::sleep(tokio::time::Duration::from_secs(user_rates_sent_seconds)).await; } }); }