From a82b4f94ac5ba07b33f0ea6b2c7aa2bdfefcd485 Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Wed, 20 Mar 2024 20:43:57 -0400 Subject: [PATCH 1/3] log retention = 2 days --- src/core/botinstance.rs | 16 ++++++++++++++++ src/main.rs | 8 ++++++++ 2 files changed, 24 insertions(+) diff --git a/src/core/botinstance.rs b/src/core/botinstance.rs index ea8e03c..d17fc2e 100644 --- a/src/core/botinstance.rs +++ b/src/core/botinstance.rs @@ -4,6 +4,7 @@ use std::sync::Arc; use tokio::sync::mpsc::UnboundedReceiver; use tokio::sync::{Mutex, RwLock}; +use tokio::time::{sleep, Duration}; use twitch_irc::login::StaticLoginCredentials; use twitch_irc::message::{PrivmsgMessage, ServerMessage}; @@ -23,6 +24,7 @@ use crate::core::identity::{ChangeResult, IdentityManager, Permissible}; use crate::core::botlog; use crate::core::chat::Chat; + #[derive(Debug, PartialEq, Eq, Hash, Clone)] pub enum ChType { Channel(String), @@ -109,6 +111,19 @@ impl BotInstance { ratelimiters.insert(Channel(String::from(chnl)), n); } + + tokio::spawn(async { + loop { + let routine_mins = 60 * 60 * 24 * 1 ; // Every 1 Day + // let routine_mins = 1; // Every 1 Minute + Log::remove_old_logs(); + Log::info(&format!("Internal Purge Routine Triggered - running every {} mins",routine_mins)); + Log::flush(); + sleep(Duration::from_secs(60 * routine_mins)).await + } + }); + + BotInstance { prefix, bot_channel: Channel(login_name), @@ -130,6 +145,7 @@ impl BotInstance { let mut msglock = botlock.incoming_messages.write().await; while let Some(message) = msglock.recv().await { + match message { ServerMessage::Notice(msg) => { botlog::notice( diff --git a/src/main.rs b/src/main.rs index 6c829b9..40b5598 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,8 +16,13 @@ pub type BotAR = Arc>; pub async fn main() { Log::set_file_ext(Extension::Log); Log::set_level(Level::Trace); + Log::set_retention_days(2); // Log::set_level(Level::Notice); + + + + let bot = BotInstance::init().await; { @@ -53,3 +58,6 @@ pub async fn main() { let pstr = botlog::fatal("ERROR : EXIT Game loop", Some("main()".to_string()), None); panic!("{}", pstr); } + + + From 7d8672913af6f045ca0bb97944c6d2f0d5b76b5c Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Wed, 20 Mar 2024 20:43:57 -0400 Subject: [PATCH 2/3] log retention = 2 days --- src/core/botinstance.rs | 16 ++++++++++++++++ src/main.rs | 8 ++++++++ 2 files changed, 24 insertions(+) diff --git a/src/core/botinstance.rs b/src/core/botinstance.rs index ea8e03c..d17fc2e 100644 --- a/src/core/botinstance.rs +++ b/src/core/botinstance.rs @@ -4,6 +4,7 @@ use std::sync::Arc; use tokio::sync::mpsc::UnboundedReceiver; use tokio::sync::{Mutex, RwLock}; +use tokio::time::{sleep, Duration}; use twitch_irc::login::StaticLoginCredentials; use twitch_irc::message::{PrivmsgMessage, ServerMessage}; @@ -23,6 +24,7 @@ use crate::core::identity::{ChangeResult, IdentityManager, Permissible}; use crate::core::botlog; use crate::core::chat::Chat; + #[derive(Debug, PartialEq, Eq, Hash, Clone)] pub enum ChType { Channel(String), @@ -109,6 +111,19 @@ impl BotInstance { ratelimiters.insert(Channel(String::from(chnl)), n); } + + tokio::spawn(async { + loop { + let routine_mins = 60 * 60 * 24 * 1 ; // Every 1 Day + // let routine_mins = 1; // Every 1 Minute + Log::remove_old_logs(); + Log::info(&format!("Internal Purge Routine Triggered - running every {} mins",routine_mins)); + Log::flush(); + sleep(Duration::from_secs(60 * routine_mins)).await + } + }); + + BotInstance { prefix, bot_channel: Channel(login_name), @@ -130,6 +145,7 @@ impl BotInstance { let mut msglock = botlock.incoming_messages.write().await; while let Some(message) = msglock.recv().await { + match message { ServerMessage::Notice(msg) => { botlog::notice( diff --git a/src/main.rs b/src/main.rs index 6c829b9..40b5598 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,8 +16,13 @@ pub type BotAR = Arc>; pub async fn main() { Log::set_file_ext(Extension::Log); Log::set_level(Level::Trace); + Log::set_retention_days(2); // Log::set_level(Level::Notice); + + + + let bot = BotInstance::init().await; { @@ -53,3 +58,6 @@ pub async fn main() { let pstr = botlog::fatal("ERROR : EXIT Game loop", Some("main()".to_string()), None); panic!("{}", pstr); } + + + From 9a95584588af555556c6a22fe3aceeb91c6a939e Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Wed, 20 Mar 2024 20:56:43 -0400 Subject: [PATCH 3/3] smol --- src/core/botinstance.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/botinstance.rs b/src/core/botinstance.rs index d17fc2e..144e8ee 100644 --- a/src/core/botinstance.rs +++ b/src/core/botinstance.rs @@ -114,7 +114,7 @@ impl BotInstance { tokio::spawn(async { loop { - let routine_mins = 60 * 60 * 24 * 1 ; // Every 1 Day + let routine_mins = 60 * 60 * 24 ; // Every 1 Day // let routine_mins = 1; // Every 1 Minute Log::remove_old_logs(); Log::info(&format!("Internal Purge Routine Triggered - running every {} mins",routine_mins));