Skip to content

Commit

Permalink
added configurable interval for user rate send events (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
arkanoider authored Nov 1, 2023
1 parent 7c52034 commit da61ce2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions settings.tpl.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
1 change: 1 addition & 0 deletions src/cli/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Settings> for Mostro {
Expand Down
8 changes: 6 additions & 2 deletions src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ pub async fn start_scheduler(rate_list: Arc<Mutex<Vec<Event>>>, client: &Client)
async fn job_update_rate_events(client: Client, rate_list: Arc<Mutex<Vec<Event>>>) {
// 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 {
Expand All @@ -44,13 +46,15 @@ async fn job_update_rate_events(client: Client, rate_list: Arc<Mutex<Vec<Event>>
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;
}
});
}
Expand Down

0 comments on commit da61ce2

Please sign in to comment.