From a059ff1c3e9d604afdddc08868173f84d1cba98d Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Tue, 13 Aug 2024 21:29:55 +0300 Subject: [PATCH] refactor(main): define timeout delays as constants --- src/main.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index a72b843..6947d73 100644 --- a/src/main.rs +++ b/src/main.rs @@ -31,6 +31,9 @@ mod task; mod tasks; mod kinds; +const UNDO_DELAY: u64 = 60; +const INACTVITY_DELAY: u64 = 200; + type Events = Vec; #[derive(Debug, Clone)] @@ -54,7 +57,7 @@ impl EventSender { { // Always flush if oldest event older than a minute or newer than now let borrow = self.queue.borrow(); - let min = Timestamp::now().sub(60u64); + let min = Timestamp::now().sub(UNDO_DELAY); if borrow.iter().any(|e| e.created_at < min || e.created_at > Timestamp::now()) { drop(borrow); debug!("Flushing event queue because it is older than a minute"); @@ -227,7 +230,7 @@ async fn main() { loop { // TODO invalid acknowledgement from bucket relay slows sending down - match rx.recv_timeout(Duration::from_secs(200)) { + match rx.recv_timeout(Duration::from_secs(INACTVITY_DELAY)) { Ok((url, mut events)) => { if 1 == 2 { client.connect_relay("").await;