From 9d94328cd67dce4d5c9796f53472d539be0f4073 Mon Sep 17 00:00:00 2001 From: mzntori Date: Fri, 29 Mar 2024 21:05:21 +0100 Subject: [PATCH 01/10] mark call that locks execbody from using that routine --- src/core/botmodules.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/core/botmodules.rs b/src/core/botmodules.rs index f4dfb18..0dba823 100644 --- a/src/core/botmodules.rs +++ b/src/core/botmodules.rs @@ -1223,10 +1223,15 @@ impl Routine { mutlock.parent_params.curr_act = mutlock.self_act_ar.to_owned().unwrap(); } + dbg!("before"); + + // `self_ar` is the routine you want to read in the execbody i think, but its used to call that execbody. + // So execbody waits for itself to finish. (self_ar.read().await.exec_body)( self_ar.read().await.parent_params.clone() ).await; - + + dbg!("after"); // (self.exec_body)( // self.parent_params.clone() // ).await; -- 2.46.0 From fcf4f3f7cfe6c94eefdb3883bb3e06e52d9895a6 Mon Sep 17 00:00:00 2001 From: mzntori Date: Fri, 29 Mar 2024 21:06:48 +0100 Subject: [PATCH 02/10] add debug implementations that helped (kinda) --- src/core/bot_actions.rs | 2 +- src/core/botinstance.rs | 3 ++- src/core/botmodules.rs | 34 +++++++++++++++++++++++++++++++++- src/core/chat.rs | 2 +- src/core/identity.rs | 2 +- 5 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/core/bot_actions.rs b/src/core/bot_actions.rs index 130be94..c7ec0c5 100644 --- a/src/core/bot_actions.rs +++ b/src/core/bot_actions.rs @@ -12,7 +12,7 @@ pub type BotAR = Arc>; pub type ActAR = Arc>; pub type RoutineAR = Arc>; -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct ExecBodyParams { pub bot : BotAR, pub msg : PrivmsgMessage, diff --git a/src/core/botinstance.rs b/src/core/botinstance.rs index 86ac8bb..2c06cea 100644 --- a/src/core/botinstance.rs +++ b/src/core/botinstance.rs @@ -40,7 +40,7 @@ pub struct Channel(pub String); use super::bot_actions::ExecBodyParams; use super::botmodules::StatusType; -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct BotManagers { pub identity: Arc>, pub chat: Chat, @@ -70,6 +70,7 @@ impl ArcBox { } } +#[derive(Debug)] pub struct BotInstance { pub prefix: char, pub bot_channel: Channel, diff --git a/src/core/botmodules.rs b/src/core/botmodules.rs index 0dba823..32e669f 100644 --- a/src/core/botmodules.rs +++ b/src/core/botmodules.rs @@ -28,6 +28,7 @@ use core::panic; use std::borrow::Borrow; use std::borrow::BorrowMut; use std::collections::HashMap; +use std::fmt::{Debug, Formatter}; use std::ops::DerefMut; use std::sync::Arc; @@ -470,6 +471,7 @@ pub enum StatusType { Disabled(StatusLvl), } +#[derive(Debug)] pub enum BotAction { C(BotCommand), L(Listener), @@ -532,6 +534,12 @@ impl BotActionTrait for BotCommand { } } +impl Debug for BotCommand { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + write!(f, "{:?} {:?} {:?} {:?} {:?}", self.module, self.command, self.alias, self.help, self.required_roles) + } +} + pub struct Listener { pub module: BotModule, pub name: String, @@ -579,6 +587,12 @@ impl BotActionTrait for Listener { } } +impl Debug for Listener { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + write!(f, "{:?} {:?} {:?}", self.module, self.name, self.help) + } +} + // #[derive(Debug, PartialEq, Eq, Hash, Clone)] #[derive(Debug, PartialEq, Eq, Hash)] pub enum RoutineAttr { @@ -617,6 +631,7 @@ pub enum RoutineAttr { */ // For some key statuses and in particular Stopping to Gracefully stop +#[derive(Debug)] pub enum RoutineSignal { Stopping, // Gracefully Stopping Stopped, // When cancelling or aborting, this also is represented by Stopped @@ -624,7 +639,6 @@ pub enum RoutineSignal { NotStarted, } -// #[derive(Debug)] pub struct Routine { pub name : String , pub module : BotModule , // from() can determine this if passed parents_params @@ -641,6 +655,23 @@ pub struct Routine { pub self_act_ar : Option , } +// implement Debug manually witouth `exec_body` since you cant debug `ExecBody`. +impl Debug for Routine { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + write!(f, "{:?}", self.name)?; + write!(f, "{:?}", self.module)?; + write!(f, "{:?}", self.channel)?; + write!(f, "{:?}", self.parent_params)?; + write!(f, "{:?}", self.join_handle)?; + write!(f, "{:?}", self.start_time)?; + write!(f, "{:?}", self.complete_iterations)?; + write!(f, "{:?}", self.remaining_iterations)?; + write!(f, "{:?}", self.routine_attr)?; + write!(f, "{:?}", self.internal_signal)?; + write!(f, "{:?}", self.self_routine_ar)?; + write!(f, "{:?}", self.self_act_ar) + } +} impl Routine { @@ -1477,6 +1508,7 @@ impl Routine { type StatusdbEntry = (ModGroup, Vec); type ModuleActions = Vec>>; +#[derive(Debug)] pub struct ModulesManager { statusdb: Arc>>, pub botactions: Arc>>, diff --git a/src/core/chat.rs b/src/core/chat.rs index a83bd8c..275ef3b 100644 --- a/src/core/chat.rs +++ b/src/core/chat.rs @@ -27,7 +27,7 @@ use super::identity; use async_recursion::async_recursion; -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct Chat { pub ratelimiters: Arc>>, // used to limit messages sent per channel pub client: TwitchIRCClient, StaticLoginCredentials>, diff --git a/src/core/identity.rs b/src/core/identity.rs index e1500eb..7a9e579 100644 --- a/src/core/identity.rs +++ b/src/core/identity.rs @@ -698,7 +698,7 @@ pub enum Permissible { type UserRolesDB = HashMap>>>; -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct IdentityManager { special_roles_users: Arc>, } -- 2.46.0 From a38c84b8f456cfb290c2d8ce9a7c51b8c8352900 Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Fri, 29 Mar 2024 23:51:41 -0400 Subject: [PATCH 03/10] smol --- src/core/bot_actions.rs | 4 +-- src/core/botmodules.rs | 34 +++++++++++++++--- src/custom/experimental/experiment003.rs | 44 ++++++++++++++++++++---- 3 files changed, 67 insertions(+), 15 deletions(-) diff --git a/src/core/bot_actions.rs b/src/core/bot_actions.rs index c7ec0c5..235637e 100644 --- a/src/core/bot_actions.rs +++ b/src/core/bot_actions.rs @@ -52,9 +52,6 @@ impl ExecBodyParams { pub async fn get_channel(&self) -> Option { - // THIS IS INCORRECT - BELOW MAY BE PULLING THE PARENT BOTACTION - // NOT THE CURRENT BOT ACTION - let curr_act = Arc::clone(&self.curr_act); let parent_act_lock = curr_act.read().await; @@ -74,6 +71,7 @@ impl ExecBodyParams { BotAction::R(r) => { // let temp = r.module.clone(); // Some(temp) + dbg!("Core > ExecBodyParams > GetChannels - routine identified"); Some(r.read().await.channel.clone()) } // _ => None diff --git a/src/core/botmodules.rs b/src/core/botmodules.rs index 32e669f..b3c8a5f 100644 --- a/src/core/botmodules.rs +++ b/src/core/botmodules.rs @@ -1232,6 +1232,10 @@ impl Routine { } + // pub async fn execute(routine:&Routine, params : ExecBodyParams) { + // (routine.exec_body)(params).await; + // } + async fn loopbody(&mut self) // [x] => 03.27 - COMPLETED { @@ -1254,15 +1258,35 @@ impl Routine { mutlock.parent_params.curr_act = mutlock.self_act_ar.to_owned().unwrap(); } - dbg!("before"); + dbg!("Core > Before Guards"); // `self_ar` is the routine you want to read in the execbody i think, but its used to call that execbody. // So execbody waits for itself to finish. - (self_ar.read().await.exec_body)( - self_ar.read().await.parent_params.clone() - ).await; + // (self_ar.read().await.exec_body)( + // self_ar.read().await.parent_params.clone() + // ).await; - dbg!("after"); + let parent_params = { + let guard1 = self_ar.read().await; + + let parent_params = guard1.parent_params.clone(); + drop(guard1); + parent_params + }; + + dbg!("Core > Guarding & Executing Child Execution Body"); + + { + let guard2 = self_ar.read().await; + (guard2.exec_body)(parent_params).await; + drop(guard2); + + } + // (self_ar.read().await.exec_body)( + // parent_params + // ).await; + + dbg!("Core > After Execution Body is completed"); // (self.exec_body)( // self.parent_params.clone() // ).await; diff --git a/src/custom/experimental/experiment003.rs b/src/custom/experimental/experiment003.rs index 41c1d65..fdcdde6 100644 --- a/src/custom/experimental/experiment003.rs +++ b/src/custom/experimental/experiment003.rs @@ -374,9 +374,9 @@ async fn test3_body(params : ExecBodyParams) { async fn rtestbody(params : ExecBodyParams) { - let guard = params.curr_act.read().await; + let guard1 = params.curr_act.read().await; { - let logmsg_botact = match *guard { + let logmsg_botact = match *guard1 { BotAction::C(_) => "command", BotAction::R(_) => "routine", BotAction::L(_) => "listener", @@ -392,7 +392,7 @@ async fn test3_body(params : ExecBodyParams) { { - let logmsg_botact = match *guard { + let logmsg_botact = match &*guard1 { BotAction::C(_) => "command 2", BotAction::R(_) => "routine 2", BotAction::L(_) => "listener 2", @@ -406,14 +406,44 @@ async fn test3_body(params : ExecBodyParams) { Log::flush(); } + // drop(guard1); + { + dbg!("Custom > within Child Custom fn - Before Critical area"); println!("Critical code area start"); // <= 03.29 - This is printed - if let BotAction::R(c) = &*guard { - println!("{:?}",c.read().await.channel); - } - println!("Critical code area end"); // <= 03.29 - ISSUE This is NOT printed + // if let BotAction::R(c) = &*guard { + // println!("{:?}",c.read().await.channel); + // } + + // let routine_channel = if let BotAction::R(c) = &*guard1 { + // dbg!("Custom > within Child Custom fn - During Critical area > Routine Guard "); + // let routineguard = c.read().await; + // Some(routineguard.channel.clone()); + // } else { + // None + // }; + + + // let chnl = match &*guard1 { + // BotAction::R(arr) => { + // dbg!("Custom > within Child Custom fn - During Critical area > Before Routine Guard "); + // let routineguard = arr.read().await; + // dbg!("Custom > within Child Custom fn - During Critical area > After Routine Guard "); + // Some(routineguard.channel.clone()) + // }, + // BotAction::C(_) | BotAction::L(_) => None , + // } ; + + let chnl = params.get_channel().await; + dbg!("Custom > within Child Custom fn - after GetChannel"); + println!("{:?}",chnl); + + + println!("Critical code area end"); // <= 03.29 - ISSUE This is NOT printed + dbg!("Custom > within Child Custom fn - Before Critical area"); + // if let BotAction::R(arr) = &*params.curr_act.read().await { // for curriter in 0..5 { // println!("tester - Routine - Completed Iterations : {}", -- 2.46.0 From 0625e7f0911652dd0b49fecf79614a4cfe18eec2 Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Sat, 30 Mar 2024 14:26:06 -0400 Subject: [PATCH 04/10] adding tokio-console --- .cargo/config.toml | 3 + Cargo.lock | 1122 +++++++++++++++++++++++++++++++++++++++++++- Cargo.toml | 4 +- src/main.rs | 3 + 4 files changed, 1117 insertions(+), 15 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index 46ba45d..365b0e8 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,4 +1,7 @@ +[build] +rustflags = ["--cfg", "tokio_unstable"] + [env] # Based on https://doc.rust-lang.org/cargo/reference/config.html OtherBots = "Supibot,buttsbot,PotatBotat,StreamElements,yuumeibot" diff --git a/Cargo.lock b/Cargo.lock index da35376..296b771 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -41,6 +41,12 @@ dependencies = [ "libc", ] +[[package]] +name = "anyhow" +version = "1.0.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0952808a6c2afd1aa8947271f3a60f1a6763c7b912d210184c5149b5cf147247" + [[package]] name = "async-recursion" version = "1.1.0" @@ -49,7 +55,29 @@ checksum = "30c5ef0ede93efbf733c1a727f3b6b5a1060bbedd5600183e66f6e4be4af0ec5" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.50", +] + +[[package]] +name = "async-stream" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd56dd203fef61ac097dd65721a419ddccb106b2d2b70ba60a6b529f03961a51" +dependencies = [ + "async-stream-impl", + "futures-core", + "pin-project-lite", +] + +[[package]] +name = "async-stream-impl" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.50", ] [[package]] @@ -60,7 +88,18 @@ checksum = "c980ee35e870bd1a4d2c8294d4c04d0499e67bca1e4b5cefcc693c2fa00caea9" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.50", +] + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi 0.1.19", + "libc", + "winapi", ] [[package]] @@ -69,6 +108,51 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "axum" +version = "0.6.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b829e4e32b91e643de6eafe82b1d90675f5874230191a4ffbc1b336dec4d6bf" +dependencies = [ + "async-trait", + "axum-core", + "bitflags 1.3.2", + "bytes", + "futures-util", + "http", + "http-body", + "hyper", + "itoa", + "matchit", + "memchr", + "mime", + "percent-encoding", + "pin-project-lite", + "rustversion", + "serde", + "sync_wrapper", + "tower", + "tower-layer", + "tower-service", +] + +[[package]] +name = "axum-core" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "759fa577a247914fd3f7f76d62972792636412fbfd634cd452f6a385a74d2d2c" +dependencies = [ + "async-trait", + "bytes", + "futures-util", + "http", + "http-body", + "mime", + "rustversion", + "tower-layer", + "tower-service", +] + [[package]] name = "backtrace" version = "0.3.69" @@ -84,6 +168,12 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.21.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" + [[package]] name = "bitflags" version = "1.3.2" @@ -102,12 +192,24 @@ version = "3.15.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ea184aa71bb362a1157c896979544cc23974e08fd265f29ea96b59f0b4a555b" +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + [[package]] name = "bytes" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" +[[package]] +name = "cassowary" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df8670b8c7b9dae1793364eafadf7239c40d669904660c5960d74cfd80b46a53" + [[package]] name = "casual_logger" version = "0.6.5" @@ -145,6 +247,119 @@ dependencies = [ "windows-targets 0.52.3", ] +[[package]] +name = "clap" +version = "3.2.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123" +dependencies = [ + "atty", + "bitflags 1.3.2", + "clap_derive", + "clap_lex", + "indexmap 1.9.3", + "once_cell", + "strsim", + "termcolor", + "textwrap", +] + +[[package]] +name = "clap_complete" +version = "3.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f7a2e0a962c45ce25afce14220bc24f9dade0a1787f185cecf96bfba7847cd8" +dependencies = [ + "clap", +] + +[[package]] +name = "clap_derive" +version = "3.2.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae6371b8bdc8b7d3959e9cf7b22d4435ef3e79e138688421ec654acf8c81b008" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "clap_lex" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" +dependencies = [ + "os_str_bytes", +] + +[[package]] +name = "color-eyre" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55146f5e46f237f7423d74111267d4597b59b0dad0ffaf7303bce9945d843ad5" +dependencies = [ + "backtrace", + "color-spantrace", + "eyre", + "indenter", + "once_cell", + "owo-colors", + "tracing-error", + "url", +] + +[[package]] +name = "color-spantrace" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd6be1b2a7e382e2b98b43b2adcca6bb0e465af0bdd38123873ae61eb17a72c2" +dependencies = [ + "once_cell", + "owo-colors", + "tracing-core", + "tracing-error", +] + +[[package]] +name = "console-api" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd326812b3fd01da5bb1af7d340d0d555fd3d4b641e7f1dfcf5962a902952787" +dependencies = [ + "futures-core", + "prost", + "prost-types", + "tonic", + "tracing-core", +] + +[[package]] +name = "console-subscriber" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7481d4c57092cd1c19dd541b92bdce883de840df30aa5d03fd48a3935c01842e" +dependencies = [ + "console-api", + "crossbeam-channel", + "crossbeam-utils", + "futures-task", + "hdrhistogram", + "humantime", + "prost-types", + "serde", + "serde_json", + "thread_local", + "tokio", + "tokio-stream", + "tonic", + "tracing", + "tracing-core", + "tracing-subscriber", +] + [[package]] name = "core-foundation" version = "0.9.4" @@ -161,6 +376,76 @@ version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" +[[package]] +name = "crc32fast" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3855a8a784b474f333699ef2bbca9db2c4a1f6d9088a90a2d25b1eb53111eaa" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "crossbeam-channel" +version = "0.5.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab3db02a9c5b5121e1e42fbdb1aeb65f5e02624cc58c43f2884c6ccac0b82f95" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" + +[[package]] +name = "crossterm" +version = "0.26.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a84cda67535339806297f1b331d6dd6320470d2a0fe65381e79ee9e156dd3d13" +dependencies = [ + "bitflags 1.3.2", + "crossterm_winapi", + "futures-core", + "libc", + "mio", + "parking_lot", + "signal-hook", + "signal-hook-mio", + "winapi", +] + +[[package]] +name = "crossterm_winapi" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acdd7c62a3665c7f6830a51635d9ac9b23ed385797f70a83bb8bafe9c572ab2b" +dependencies = [ + "winapi", +] + +[[package]] +name = "dirs" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059" +dependencies = [ + "dirs-sys", +] + +[[package]] +name = "dirs-sys" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6" +dependencies = [ + "libc", + "redox_users", + "winapi", +] + [[package]] name = "dotenv" version = "0.15.0" @@ -182,9 +467,15 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn", + "syn 2.0.50", ] +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + [[package]] name = "errno" version = "0.3.8" @@ -195,12 +486,38 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "eyre" +version = "0.6.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cd915d99f24784cdc19fd37ef22b97e3ff0ae756c7e492e9fbfe897d61e2aec" +dependencies = [ + "indenter", + "once_cell", +] + [[package]] name = "fastrand" version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" +[[package]] +name = "flate2" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46303f565772937ffe1d394a4fac6f411c6013172fadde9dcdb1e147a086940e" +dependencies = [ + "crc32fast", + "miniz_oxide", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + [[package]] name = "forcebot_rs" version = "0.1.0" @@ -209,10 +526,12 @@ dependencies = [ "async-trait", "casual_logger", "chrono", + "console-subscriber", "dotenv", "futures", "rand", "tokio", + "tokio-console", "twitch-irc", ] @@ -231,6 +550,15 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + [[package]] name = "futures" version = "0.3.30" @@ -287,7 +615,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.50", ] [[package]] @@ -337,12 +665,147 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" +[[package]] +name = "h2" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fbd2820c5e49886948654ab546d0688ff24530286bdcf8fca3cefb16d4618eb" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http", + "indexmap 2.2.6", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + +[[package]] +name = "hashbrown" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" + +[[package]] +name = "hdrhistogram" +version = "7.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "765c9198f173dd59ce26ff9f95ef0aafd0a0fe01fb9d72841bc5066a4c06511d" +dependencies = [ + "base64", + "byteorder", + "flate2", + "nom", + "num-traits", +] + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + [[package]] name = "hermit-abi" version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "379dada1584ad501b383485dd706b8afb7a70fcbc7f4da7d780638a5a6124a60" +[[package]] +name = "http" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "601cbb57e577e2f5ef5be8e7b83f0f63994f25aa94d673e54a92d5c516d101f1" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" +dependencies = [ + "bytes", + "http", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" + +[[package]] +name = "httpdate" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" + +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + +[[package]] +name = "hyper" +version = "0.14.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf96e135eb83a2a8ddf766e426a841d8ddd7449d5f00d34ea02b41d2f19eef80" +dependencies = [ + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", + "want", +] + +[[package]] +name = "hyper-timeout" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbb958482e8c7be4bc3cf272a766a2b0bf1a6755e7a6ae777f017a31d11b13b1" +dependencies = [ + "hyper", + "pin-project-lite", + "tokio", + "tokio-io-timeout", +] + [[package]] name = "iana-time-zone" version = "0.1.60" @@ -366,6 +829,57 @@ dependencies = [ "cc", ] +[[package]] +name = "idna" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "indenter" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" + +[[package]] +name = "indexmap" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" +dependencies = [ + "autocfg", + "hashbrown 0.12.3", +] + +[[package]] +name = "indexmap" +version = "2.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" +dependencies = [ + "equivalent", + "hashbrown 0.14.3", +] + +[[package]] +name = "itertools" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + [[package]] name = "js-sys" version = "0.3.68" @@ -387,6 +901,17 @@ version = "0.2.153" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +[[package]] +name = "libredox" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85c833ca1e66078851dba29046874e38f08b2c883700aa29a03ddd3b23814ee8" +dependencies = [ + "bitflags 2.4.2", + "libc", + "redox_syscall", +] + [[package]] name = "linux-raw-sys" version = "0.4.13" @@ -409,12 +934,39 @@ version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" +[[package]] +name = "matchers" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" +dependencies = [ + "regex-automata 0.1.10", +] + +[[package]] +name = "matchit" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" + [[package]] name = "memchr" version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + [[package]] name = "miniz_oxide" version = "0.7.2" @@ -431,6 +983,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f3d0b296e374a4e6f3c7b0a1f5a51d748a0d34c85e7dc48fc3fa9a87657fe09" dependencies = [ "libc", + "log", "wasi", "windows-sys 0.48.0", ] @@ -453,6 +1006,26 @@ dependencies = [ "tempfile", ] +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + +[[package]] +name = "nu-ansi-term" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +dependencies = [ + "overload", + "winapi", +] + [[package]] name = "num-traits" version = "0.2.18" @@ -468,7 +1041,7 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" dependencies = [ - "hermit-abi", + "hermit-abi 0.3.8", "libc", ] @@ -510,7 +1083,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.50", ] [[package]] @@ -531,6 +1104,24 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "os_str_bytes" +version = "6.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2355d85b9a3786f481747ced0e0ff2ba35213a1f9bd406ed906554d7af805a1" + +[[package]] +name = "overload" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + +[[package]] +name = "owo-colors" +version = "3.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" + [[package]] name = "parking_lot" version = "0.12.1" @@ -554,6 +1145,32 @@ dependencies = [ "windows-targets 0.48.5", ] +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "pin-project" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.50", +] + [[package]] name = "pin-project-lite" version = "0.2.13" @@ -578,6 +1195,30 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn 1.0.109", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + [[package]] name = "proc-macro2" version = "1.0.78" @@ -587,6 +1228,38 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "prost" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "146c289cda302b98a28d40c8b3b90498d6e526dd24ac2ecea73e4e491685b94a" +dependencies = [ + "bytes", + "prost-derive", +] + +[[package]] +name = "prost-derive" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "efb6c9a1dd1def8e2124d17e83a20af56f1570d6c2d2bd9e266ccb768df3840e" +dependencies = [ + "anyhow", + "itertools", + "proc-macro2", + "quote", + "syn 2.0.50", +] + +[[package]] +name = "prost-types" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "193898f59edcf43c26227dcd4c8427f00d99d61e95dcde58dabd49fa291d470e" +dependencies = [ + "prost", +] + [[package]] name = "quote" version = "1.0.35" @@ -626,6 +1299,19 @@ dependencies = [ "getrandom", ] +[[package]] +name = "ratatui" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcc0d032bccba900ee32151ec0265667535c230169f5a011154cdcd984e16829" +dependencies = [ + "bitflags 1.3.2", + "cassowary", + "crossterm", + "unicode-segmentation", + "unicode-width", +] + [[package]] name = "redox_syscall" version = "0.4.1" @@ -635,6 +1321,17 @@ dependencies = [ "bitflags 1.3.2", ] +[[package]] +name = "redox_users" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a18479200779601e498ada4e8c1e1f50e3ee19deb0259c25825a98b5603b2cb4" +dependencies = [ + "getrandom", + "libredox", + "thiserror", +] + [[package]] name = "regex" version = "1.10.3" @@ -643,8 +1340,17 @@ checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15" dependencies = [ "aho-corasick", "memchr", - "regex-automata", - "regex-syntax", + "regex-automata 0.4.5", + "regex-syntax 0.8.2", +] + +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +dependencies = [ + "regex-syntax 0.6.29", ] [[package]] @@ -655,9 +1361,15 @@ checksum = "5bb987efffd3c6d0d8f5f89510bb458559eab11e4f869acb20bf845e016259cd" dependencies = [ "aho-corasick", "memchr", - "regex-syntax", + "regex-syntax 0.8.2", ] +[[package]] +name = "regex-syntax" +version = "0.6.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" + [[package]] name = "regex-syntax" version = "0.8.2" @@ -683,6 +1395,18 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "rustversion" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" + +[[package]] +name = "ryu" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" + [[package]] name = "schannel" version = "0.1.23" @@ -721,6 +1445,67 @@ dependencies = [ "libc", ] +[[package]] +name = "serde" +version = "1.0.197" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.197" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.50", +] + +[[package]] +name = "serde_json" +version = "1.0.115" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12dc5c46daa8e9fdf4f5e71b6cf9a53f2487da0e86e55808e2d35539666497dd" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "signal-hook" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8621587d4798caf8eb44879d42e56b9a93ea5dcd315a6487c357130095b62801" +dependencies = [ + "libc", + "signal-hook-registry", +] + +[[package]] +name = "signal-hook-mio" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29ad2e15f37ec9a6cc544097b78a1ec90001e9f71b81338ca39f430adaca99af" +dependencies = [ + "libc", + "mio", + "signal-hook", +] + [[package]] name = "signal-hook-registry" version = "1.4.1" @@ -755,6 +1540,23 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "syn" version = "2.0.50" @@ -766,6 +1568,12 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "sync_wrapper" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" + [[package]] name = "tempfile" version = "3.10.0" @@ -778,6 +1586,21 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "termcolor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "textwrap" +version = "0.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23d434d3f8967a09480fb04132ebe0a3e088c173e6d0ee7897abbdf4eab0f8b9" + [[package]] name = "thiserror" version = "1.0.57" @@ -795,9 +1618,34 @@ checksum = "a953cb265bef375dae3de6663da4d3804eee9682ea80d8e2542529b73c531c81" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.50", ] +[[package]] +name = "thread_local" +version = "1.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c" +dependencies = [ + "cfg-if", + "once_cell", +] + +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + [[package]] name = "tokio" version = "1.36.0" @@ -814,9 +1662,50 @@ dependencies = [ "signal-hook-registry", "socket2", "tokio-macros", + "tracing", "windows-sys 0.48.0", ] +[[package]] +name = "tokio-console" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5ff40e8df801b383b8666967ec4aee8dc516f376d06d0e5a9f93f310763e6d2" +dependencies = [ + "atty", + "clap", + "clap_complete", + "color-eyre", + "console-api", + "crossterm", + "dirs", + "futures", + "h2", + "hdrhistogram", + "humantime", + "once_cell", + "prost-types", + "ratatui", + "regex", + "serde", + "tokio", + "toml", + "tonic", + "tower", + "tracing", + "tracing-subscriber", +] + +[[package]] +name = "tokio-io-timeout" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30b74022ada614a1b4834de765f9bb43877f910cc8ce4be40e89042c9223a8bf" +dependencies = [ + "pin-project-lite", + "tokio", +] + [[package]] name = "tokio-macros" version = "2.2.0" @@ -825,7 +1714,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.50", ] [[package]] @@ -863,12 +1752,81 @@ dependencies = [ "tracing", ] +[[package]] +name = "toml" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" +dependencies = [ + "serde", +] + +[[package]] +name = "tonic" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d560933a0de61cf715926b9cac824d4c883c2c43142f787595e48280c40a1d0e" +dependencies = [ + "async-stream", + "async-trait", + "axum", + "base64", + "bytes", + "h2", + "http", + "http-body", + "hyper", + "hyper-timeout", + "percent-encoding", + "pin-project", + "prost", + "tokio", + "tokio-stream", + "tower", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" +dependencies = [ + "futures-core", + "futures-util", + "indexmap 1.9.3", + "pin-project", + "pin-project-lite", + "rand", + "slab", + "tokio", + "tokio-util", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-layer" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c20c8dbed6283a09604c3e69b4b7eeb54e298b8a600d4d5ecb5ad39de609f1d0" + +[[package]] +name = "tower-service" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" + [[package]] name = "tracing" version = "0.1.40" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ + "log", "pin-project-lite", "tracing-attributes", "tracing-core", @@ -882,7 +1840,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.50", ] [[package]] @@ -892,8 +1850,54 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" dependencies = [ "once_cell", + "valuable", ] +[[package]] +name = "tracing-error" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d686ec1c0f384b1277f097b2f279a2ecc11afe8c133c1aabf036a27cb4cd206e" +dependencies = [ + "tracing", + "tracing-subscriber", +] + +[[package]] +name = "tracing-log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" +dependencies = [ + "matchers", + "nu-ansi-term", + "once_cell", + "regex", + "sharded-slab", + "smallvec", + "thread_local", + "tracing", + "tracing-core", + "tracing-log", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + [[package]] name = "twitch-irc" version = "5.0.1" @@ -915,18 +1919,77 @@ dependencies = [ "tracing", ] +[[package]] +name = "unicode-bidi" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" + [[package]] name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "unicode-normalization" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-segmentation" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" + +[[package]] +name = "unicode-width" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" + +[[package]] +name = "url" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + [[package]] name = "vcpkg" version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -954,7 +2017,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn", + "syn 2.0.50", "wasm-bindgen-shared", ] @@ -976,7 +2039,7 @@ checksum = "642f325be6301eb8107a83d12a8ac6c1e1c54345a7ef1a9261962dfefda09e66" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.50", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -987,6 +2050,37 @@ version = "0.2.91" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4f186bd2dcf04330886ce82d6f33dd75a7bfcf69ecf5763b89fcde53b6ac9838" +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" +dependencies = [ + "winapi", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + [[package]] name = "windows-core" version = "0.52.0" diff --git a/Cargo.toml b/Cargo.toml index f3f7724..0d96343 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" [dependencies] dotenv = "0.15.0" -tokio = { version = "1.33.0", features = ["full"] } +tokio = { version = "1.33.0", features = ["full", "tracing"] } twitch-irc = "5.0.1" rand = { version = "0.8.5", features = [] } futures = "0.3" @@ -15,6 +15,8 @@ async-trait = "0.1.77" async-recursion = "1.1.0" casual_logger = "0.6.5" chrono = "0.4.35" +tokio-console = "0.1.10" +console-subscriber = "0.2.0" [lib] diff --git a/src/main.rs b/src/main.rs index 6bc6c0f..866fc38 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,6 +14,9 @@ pub type BotAR = Arc>; #[tokio::main] pub async fn main() { + console_subscriber::init(); + + Log::set_file_ext(Extension::Log); Log::set_level(Level::Trace); Log::set_retention_days(2); -- 2.46.0 From 745ac915229d97e8b853a91cf4349179f0d778e5 Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Sat, 30 Mar 2024 14:26:39 -0400 Subject: [PATCH 05/10] addl debug --- src/core/bot_actions.rs | 16 +++++++++++++--- src/core/botmodules.rs | 20 +++++++++++++++++--- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/core/bot_actions.rs b/src/core/bot_actions.rs index 235637e..37f2445 100644 --- a/src/core/bot_actions.rs +++ b/src/core/bot_actions.rs @@ -56,7 +56,7 @@ impl ExecBodyParams { let curr_act = Arc::clone(&self.curr_act); let parent_act_lock = curr_act.read().await; let act = &(*parent_act_lock); - match act { + let out = match act { BotAction::C(_) => { // let temp = c.module.clone(); // Some(temp) @@ -72,10 +72,20 @@ impl ExecBodyParams { // let temp = r.module.clone(); // Some(temp) dbg!("Core > ExecBodyParams > GetChannels - routine identified"); - Some(r.read().await.channel.clone()) + dbg!(">> BotActionAR - RwLock from botmodules.rs::929:46 - current_readers = 1 "); + dbg!(">> RoutineAR - RwLock from botmodules.rs::1261:32 - current_readers = 1"); + dbg!(">> join_handle - RwLock from botmodules.rs::1226:46 - current_readers = 0"); + dbg!(">> BotInstanceAR - RwLock from botinstance.rs::150:28 - current_readers = 3 "); + // => 03.30 - Just before deadlock + let out = Some(r.read().await.channel.clone()); + + // => 03.30 - This isn't reached because of the Deadlock + dbg!(">> Just after Potential Deadlock Lock"); + out } // _ => None - } + }; + out } diff --git a/src/core/botmodules.rs b/src/core/botmodules.rs index b3c8a5f..65d902a 100644 --- a/src/core/botmodules.rs +++ b/src/core/botmodules.rs @@ -1221,9 +1221,11 @@ impl Routine { { // Recommendation to ensure a clean update is to use one write() lock that was awaited // - We can isolate the write lock by ensuring it's in it's own block - let mut lock = trg_routine_arout.write().await; + // => 03.30 - involved with Problem Deadlock Current Readers = 0 + let mut lock = trg_routine_arout.write().await; lock.join_handle = Some(Arc::new(RwLock::new(join_handle))); lock.internal_signal = RoutineSignal::Started; + drop(lock); // => 03.30 - added this to try to address Deadlock issue } trg_routine_arout.write().await.internal_signal = RoutineSignal::Started; @@ -1236,6 +1238,11 @@ impl Routine { // (routine.exec_body)(params).await; // } + + // fn (){ + + // } + async fn loopbody(&mut self) // [x] => 03.27 - COMPLETED { @@ -1248,14 +1255,18 @@ impl Routine { ); Log::flush(); - - let self_ar = Arc::new(RwLock::new(self)); + + // => 03.30 - involved with Problem Deadlock Current Readers = 1 + // - Below self appears to be a Arc> + let self_ar = Arc::new(RwLock::new(self)); + { let mut mutlock = self_ar.write().await; mutlock.parent_params.parent_act = Some(mutlock.parent_params.curr_act.clone()); mutlock.parent_params.curr_act = mutlock.self_act_ar.to_owned().unwrap(); + drop(mutlock); // => 03.30 - Added to address Deadlock issue } dbg!("Core > Before Guards"); @@ -1275,6 +1286,9 @@ impl Routine { }; dbg!("Core > Guarding & Executing Child Execution Body"); + dbg!(">> BotActionAR - RwLock from botmodules.rs::929:46 - current_readers = 0 "); + dbg!(">> RoutineAR - RwLock from botmodules.rs::1261:32 - current_readers = Not Listed"); + dbg!(">> BotInstanceAR - RwLock from botinstance.rs::150:28 - current_readers = 3 "); { let guard2 = self_ar.read().await; -- 2.46.0 From 4719b93ce553c6883ea87d4bc6478e479f1fd5c5 Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Sat, 30 Mar 2024 19:25:07 -0400 Subject: [PATCH 06/10] addl debug --- src/core/bot_actions.rs | 45 ++++++++++++++++++++---- src/core/botmodules.rs | 35 +++++++++++++++--- src/custom/experimental/experiment003.rs | 4 +-- 3 files changed, 72 insertions(+), 12 deletions(-) diff --git a/src/core/bot_actions.rs b/src/core/bot_actions.rs index 37f2445..fae3d3b 100644 --- a/src/core/bot_actions.rs +++ b/src/core/bot_actions.rs @@ -52,10 +52,33 @@ impl ExecBodyParams { pub async fn get_channel(&self) -> Option { + dbg!("Core > ExecBodyParams > GetChannels START"); + dbg!("!! [x] Document - After SUCCESS message was sent to chat"); + dbg!(">> BotActionAR - RwLock from botmodules.rs::929:46 - current_readers = 1 "); + dbg!(">> RoutineAR - RwLock from botmodules.rs::1261:32 - current_readers = 1 "); + dbg!(">> join_handle - RwLock from botmodules.rs::1226:46 - current_readers = 0 "); + dbg!(">> BotInstanceAR - RwLock from botinstance.rs::150:28 - current_readers = 2"); + let curr_act = Arc::clone(&self.curr_act); - let parent_act_lock = curr_act.read().await; - let act = &(*parent_act_lock); + let curr_act_lock = curr_act.read().await; + + dbg!("Core > ExecBodyParams > After Creating ExecBodyParams.current_act.read() Guard "); + dbg!("!! [x] Document - After SUCCESS message was sent to chat"); + dbg!(">> BotActionAR - RwLock from botmodules.rs::929:46 - current_readers = 1 "); + dbg!(">> RoutineAR - RwLock from botmodules.rs::1261:32 - current_readers = 1 "); + dbg!(">> join_handle - RwLock from botmodules.rs::1226:46 - current_readers = 0 "); + dbg!(">> BotInstanceAR - RwLock from botinstance.rs::150:28 - current_readers = 2"); + + let act = &(*curr_act_lock); + + dbg!("Core > ExecBodyParams > Using the Read Guard "); + dbg!("!! [x] Document - After SUCCESS message was sent to chat"); + dbg!(">> BotActionAR - RwLock from botmodules.rs::929:46 - current_readers = 1 "); + dbg!(">> RoutineAR - RwLock from botmodules.rs::1261:32 - current_readers = 1"); + dbg!(">> join_handle - RwLock from botmodules.rs::1226:46 - current_readers = Not Listed "); + dbg!(">> BotInstanceAR - RwLock from botinstance.rs::150:28 - current_readers = 2"); + let out = match act { BotAction::C(_) => { // let temp = c.module.clone(); @@ -72,12 +95,22 @@ impl ExecBodyParams { // let temp = r.module.clone(); // Some(temp) dbg!("Core > ExecBodyParams > GetChannels - routine identified"); - dbg!(">> BotActionAR - RwLock from botmodules.rs::929:46 - current_readers = 1 "); - dbg!(">> RoutineAR - RwLock from botmodules.rs::1261:32 - current_readers = 1"); + dbg!("!! [x] Document"); + dbg!(">> BotActionAR - RwLock from botmodules.rs::930:46 - current_readers = 2"); + dbg!(">> RoutineAR - RwLock from botmodules.rs::1262:32 - current_readers = 1"); dbg!(">> join_handle - RwLock from botmodules.rs::1226:46 - current_readers = 0"); - dbg!(">> BotInstanceAR - RwLock from botinstance.rs::150:28 - current_readers = 3 "); + dbg!(">> BotInstanceAR - RwLock from botinstance.rs::150:28 - current_readers = 1"); // => 03.30 - Just before deadlock - let out = Some(r.read().await.channel.clone()); + // dbg!("ISSUE : RoutineAR - RwLock from botmodules.rs::1261:32 - current_readers = 1"); + // let out = Some(r.read().await.channel.clone()); + + let guard = r.read().await; + + dbg!("ISSUE> Never makes it after the read guard"); + + let channel = guard.channel.clone(); + drop(guard); + let out = Some(channel); // => 03.30 - This isn't reached because of the Deadlock dbg!(">> Just after Potential Deadlock Lock"); diff --git a/src/core/botmodules.rs b/src/core/botmodules.rs index 65d902a..5a45979 100644 --- a/src/core/botmodules.rs +++ b/src/core/botmodules.rs @@ -507,6 +507,7 @@ pub struct BotCommand { impl BotCommand { pub async fn execute(&self, params : ExecBodyParams) { + // This is how BotCommand implements their Working exec_body (*self.exec_body)(params).await; } } @@ -643,7 +644,7 @@ pub struct Routine { pub name : String , pub module : BotModule , // from() can determine this if passed parents_params pub channel : Channel , // Requiring some channel context - exec_body: bot_actions::actions_util::ExecBody, + exec_body: Arc>, pub parent_params : ExecBodyParams , pub join_handle : Option>>> , start_time : Option> , @@ -895,7 +896,7 @@ impl Routine { module : BotModule , channel : Channel, routine_attr : Vec , - exec_body : bot_actions::actions_util::ExecBody , + exec_body : Arc> , parent_params : ExecBodyParams ) -> Result< Arc>, @@ -1285,17 +1286,43 @@ impl Routine { parent_params }; - dbg!("Core > Guarding & Executing Child Execution Body"); + dbg!("Core > Guarding and will Execute Child Execution Body"); dbg!(">> BotActionAR - RwLock from botmodules.rs::929:46 - current_readers = 0 "); dbg!(">> RoutineAR - RwLock from botmodules.rs::1261:32 - current_readers = Not Listed"); dbg!(">> BotInstanceAR - RwLock from botinstance.rs::150:28 - current_readers = 3 "); + // { + // // The below starts the Read Lock that conlicts + // let guard2 = self_ar.read().await; + + // dbg!("Core > Guarded & Executing Child Execution Body"); + // dbg!("!! [x] Document "); + // dbg!(">> BotActionAR - RwLock from botmodules.rs::929:46 - current_readers = 0 "); + // dbg!(">> RoutineAR - RwLock from botmodules.rs::1261:32 - current_readers = 1"); + // dbg!(">> BotInstanceAR - RwLock from botinstance.rs::150:28 - current_readers = 2 "); + // // this way seems to be having issues for Routine > Loopbody + // // in particular, because by this point we have a ReadGuard on Routine + // // somehow the read guard is conflicting with a read guard in the underlying + // // fn? + // (guard2.exec_body)(parent_params).await; + // drop(guard2); + + // } + { + let guard2 = self_ar.read().await; - (guard2.exec_body)(parent_params).await; + let exec_body_ar = guard2.exec_body.clone(); drop(guard2); + let guard3 = exec_body_ar.read().await; + (guard3)(parent_params).await; + drop(guard3); + } + + + // (self_ar.read().await.exec_body)( // parent_params // ).await; diff --git a/src/custom/experimental/experiment003.rs b/src/custom/experimental/experiment003.rs index fdcdde6..0be50a3 100644 --- a/src/custom/experimental/experiment003.rs +++ b/src/custom/experimental/experiment003.rs @@ -279,7 +279,7 @@ async fn countdown_chnl_v1(params : ExecBodyParams) { module, channel.unwrap(), routine_attr, - exec_body, + Arc::new(RwLock::new(exec_body)), params.clone() ).await { let newr_ar = newr.clone(); @@ -475,7 +475,7 @@ async fn test3_body(params : ExecBodyParams) { module, channel.unwrap(), routine_attr, - exec_body, + Arc::new(RwLock::new(exec_body)), params.clone() ).await; -- 2.46.0 From 000094e9c4e126ca8036abafa55d639cbc714c3e Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Sun, 31 Mar 2024 14:13:20 -0400 Subject: [PATCH 07/10] attempt blocking at getchannel failed --- src/core/bot_actions.rs | 10 ++++++++++ src/custom/experimental/experiment003.rs | 3 +++ 2 files changed, 13 insertions(+) diff --git a/src/core/bot_actions.rs b/src/core/bot_actions.rs index fae3d3b..9ad7eea 100644 --- a/src/core/bot_actions.rs +++ b/src/core/bot_actions.rs @@ -51,6 +51,7 @@ impl ExecBodyParams { } pub async fn get_channel(&self) -> Option { + // pub fn get_channel(&self) -> Option { dbg!("Core > ExecBodyParams > GetChannels START"); dbg!("!! [x] Document - After SUCCESS message was sent to chat"); @@ -63,6 +64,14 @@ impl ExecBodyParams { let curr_act = Arc::clone(&self.curr_act); let curr_act_lock = curr_act.read().await; + // Note : The below `curr_act.blocking_read()` is not possible. I get the following + // during runtime in this areas + /* + thread 'tokio-runtime-worker' panicked at src\core\bot_actions.rs:66:38: +Cannot block the current thread from within a runtime. This happens because a function attempted to block the current thread while the thread is being used to drive asynchronous tasks. + */ + // let curr_act_lock = curr_act.blocking_read(); + dbg!("Core > ExecBodyParams > After Creating ExecBodyParams.current_act.read() Guard "); dbg!("!! [x] Document - After SUCCESS message was sent to chat"); dbg!(">> BotActionAR - RwLock from botmodules.rs::929:46 - current_readers = 1 "); @@ -105,6 +114,7 @@ impl ExecBodyParams { // let out = Some(r.read().await.channel.clone()); let guard = r.read().await; + // let guard = r.blocking_read(); dbg!("ISSUE> Never makes it after the read guard"); diff --git a/src/custom/experimental/experiment003.rs b/src/custom/experimental/experiment003.rs index 0be50a3..774e24b 100644 --- a/src/custom/experimental/experiment003.rs +++ b/src/custom/experimental/experiment003.rs @@ -141,6 +141,7 @@ async fn countdown_chnl_v1(params : ExecBodyParams) { // let parentmodule = params.get_parent_module().await; let module = params.get_module().await; + // let channel = params.get_channel().await; let channel = params.get_channel().await; let routine_attr = vec![ // RoutineAttr::RunOnce @@ -359,6 +360,7 @@ async fn test3_body(params : ExecBodyParams) { // let parentmodule = params.get_parent_module().await; let module = params.get_module().await; + // let channel = params.get_channel().await; let channel = params.get_channel().await; let routine_attr = vec![ RoutineAttr::RunOnce @@ -436,6 +438,7 @@ async fn test3_body(params : ExecBodyParams) { // BotAction::C(_) | BotAction::L(_) => None , // } ; + // let chnl = params.get_channel().await; let chnl = params.get_channel().await; dbg!("Custom > within Child Custom fn - after GetChannel"); println!("{:?}",chnl); -- 2.46.0 From fa5de03bae027336c17373dd463832264b22206d Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Sun, 31 Mar 2024 16:38:11 -0400 Subject: [PATCH 08/10] used blocking instead of async in some calls --- src/core/bot_actions.rs | 17 +++-- src/core/botmodules.rs | 93 +++++++++++++++++------- src/custom/experimental/experiment003.rs | 90 ++++++++++++++++------- src/main.rs | 9 ++- 4 files changed, 147 insertions(+), 62 deletions(-) diff --git a/src/core/bot_actions.rs b/src/core/bot_actions.rs index 9ad7eea..7775beb 100644 --- a/src/core/bot_actions.rs +++ b/src/core/bot_actions.rs @@ -50,8 +50,8 @@ impl ExecBodyParams { } } - pub async fn get_channel(&self) -> Option { - // pub fn get_channel(&self) -> Option { + // pub async fn get_channel(&self) -> Option { + pub fn get_channel(&self) -> Option { dbg!("Core > ExecBodyParams > GetChannels START"); dbg!("!! [x] Document - After SUCCESS message was sent to chat"); @@ -62,7 +62,7 @@ impl ExecBodyParams { let curr_act = Arc::clone(&self.curr_act); - let curr_act_lock = curr_act.read().await; + // let curr_act_lock = curr_act.read().await; // Note : The below `curr_act.blocking_read()` is not possible. I get the following // during runtime in this areas @@ -70,7 +70,7 @@ impl ExecBodyParams { thread 'tokio-runtime-worker' panicked at src\core\bot_actions.rs:66:38: Cannot block the current thread from within a runtime. This happens because a function attempted to block the current thread while the thread is being used to drive asynchronous tasks. */ - // let curr_act_lock = curr_act.blocking_read(); + let curr_act_lock = curr_act.blocking_read(); dbg!("Core > ExecBodyParams > After Creating ExecBodyParams.current_act.read() Guard "); dbg!("!! [x] Document - After SUCCESS message was sent to chat"); @@ -113,10 +113,13 @@ Cannot block the current thread from within a runtime. This happens because a fu // dbg!("ISSUE : RoutineAR - RwLock from botmodules.rs::1261:32 - current_readers = 1"); // let out = Some(r.read().await.channel.clone()); - let guard = r.read().await; - // let guard = r.blocking_read(); + + dbg!("ISSUE > Never makes it after the following read guard"); - dbg!("ISSUE> Never makes it after the read guard"); + // let guard = r.read().await; + let guard = r.blocking_read(); + + dbg!("ISSUE RESOLVED > If passed htis point"); let channel = guard.channel.clone(); drop(guard); diff --git a/src/core/botmodules.rs b/src/core/botmodules.rs index 5a45979..5bc9f0a 100644 --- a/src/core/botmodules.rs +++ b/src/core/botmodules.rs @@ -644,8 +644,11 @@ pub struct Routine { pub name : String , pub module : BotModule , // from() can determine this if passed parents_params pub channel : Channel , // Requiring some channel context - exec_body: Arc>, - pub parent_params : ExecBodyParams , + // exec_body: Arc>, + // exec_body : fn(ExecBodyParams), + exec_body : fn(Arc>), + // pub parent_params : ExecBodyParams , + pub parent_params : Arc> , pub join_handle : Option>>> , start_time : Option> , pub complete_iterations : i64 , @@ -896,8 +899,9 @@ impl Routine { module : BotModule , channel : Channel, routine_attr : Vec , - exec_body : Arc> , - parent_params : ExecBodyParams + // exec_body : Arc> , + exec_body : fn(Arc>) , + parent_params : Arc> ) -> Result< Arc>, String @@ -1014,7 +1018,7 @@ impl Routine { Some(format!( "Routine > start() > (In Tokio Spawn)", )), - Some(&trg_routine_ar.read().await.parent_params.msg), + Some(&trg_routine_ar.read().await.parent_params.read().await.msg), ); Log::flush(); @@ -1027,7 +1031,7 @@ impl Routine { Some(format!( "Routine > start() > (In Tokio Spawn)", )), - Some(&trg_routine_ar.read().await.parent_params.msg), + Some(&trg_routine_ar.read().await.parent_params.read().await.msg), ); Log::flush(); @@ -1110,7 +1114,7 @@ impl Routine { "Routine > start() > (In Tokio Spawn) > {:?}", trg_routine_ar.read().await.module )), - Some(&trg_routine_ar.read().await.parent_params.msg), + Some(&trg_routine_ar.read().await.parent_params.read().await.msg), ); if let Some(dur) = delayduration { @@ -1119,6 +1123,8 @@ impl Routine { { // [x] Loop Initialization - Prior to Loop that calls Custom Routine Execution Body + + let mut a = trg_routine_ar.write().await; a.start_time = Some(chrono::offset::Local::now()); @@ -1129,15 +1135,33 @@ impl Routine { { a.remaining_iterations = Some(iternum); } + drop(a); } + loop { // [x] Routine loop // [x] execution body // trg_routine_ar.read().await.loopbody().await; { - trg_routine_ar.write().await.loopbody().await; + + let trg_routine_ar_clone = trg_routine_ar.clone(); + // trg_routine_ar.write().await.loopbody().await; + let loopbodyspawn = tokio::task::spawn_blocking( move || { + // let routine_ar_clone = Arc::clone(&trg_routine_ar); + // trg_routine_ar + // trg_routine_ar_clone.blocking_write().loopbody(); + let guard1 = trg_routine_ar_clone.blocking_read(); + guard1.loopbody(); + drop(guard1); + }); + + loopbodyspawn.await.unwrap(); + + + // trg_routine_ar.write().await.loopbody() + } @@ -1156,6 +1180,7 @@ impl Routine { if i > 0 { a.remaining_iterations = Some(i-1) ; } else { break ; } // if remaining iterations is 0, exit } + drop(a); } @@ -1184,6 +1209,8 @@ impl Routine { } + dbg!("SUCCESS! Routinecompleted"); + botlog::trace( format!( @@ -1196,7 +1223,7 @@ impl Routine { "Routine > start() > (In Tokio Spawn) > {:?}", trg_routine_ar.read().await.module )), - Some(&trg_routine_ar.read().await.parent_params.msg), + Some(&trg_routine_ar.read().await.parent_params.read().await.msg), ); botlog::trace( @@ -1211,7 +1238,7 @@ impl Routine { "Routine > start() > (In Tokio Spawn) > {:?}", trg_routine_ar.read().await.module )), - Some(&trg_routine_ar.read().await.parent_params.msg), + Some(&trg_routine_ar.read().await.parent_params.read().await.msg), ); Log::flush(); @@ -1229,7 +1256,7 @@ impl Routine { drop(lock); // => 03.30 - added this to try to address Deadlock issue } - trg_routine_arout.write().await.internal_signal = RoutineSignal::Started; + // trg_routine_arout.write().await.internal_signal = RoutineSignal::Started; return Ok(trg_routine_arout); @@ -1244,7 +1271,9 @@ impl Routine { // } - async fn loopbody(&mut self) + // async fn loopbody(&mut self) + // fn loopbody(&mut self) + fn loopbody(&self) // [x] => 03.27 - COMPLETED { botlog::trace( @@ -1260,15 +1289,19 @@ impl Routine { // => 03.30 - involved with Problem Deadlock Current Readers = 1 // - Below self appears to be a Arc> let self_ar = Arc::new(RwLock::new(self)); - + + // => 03.31 - Temporarily removing the current_act / parrent_act functionality + /* { - let mut mutlock = self_ar.write().await; + // let mutlock = self_ar.read().await; + let mutlock = self_ar.blocking_read(); - mutlock.parent_params.parent_act = Some(mutlock.parent_params.curr_act.clone()); - mutlock.parent_params.curr_act = mutlock.self_act_ar.to_owned().unwrap(); + mutlock.parent_params.blocking_write().parent_act = Some(mutlock.parent_params.blocking_read().curr_act.clone()); + mutlock.parent_params.blocking_write().curr_act = mutlock.self_act_ar.to_owned().unwrap(); drop(mutlock); // => 03.30 - Added to address Deadlock issue } + */ dbg!("Core > Before Guards"); @@ -1279,7 +1312,7 @@ impl Routine { // ).await; let parent_params = { - let guard1 = self_ar.read().await; + let guard1 = self_ar.blocking_read(); let parent_params = guard1.parent_params.clone(); drop(guard1); @@ -1311,12 +1344,15 @@ impl Routine { { - let guard2 = self_ar.read().await; + let guard2 = self_ar.blocking_read(); let exec_body_ar = guard2.exec_body.clone(); drop(guard2); - let guard3 = exec_body_ar.read().await; - (guard3)(parent_params).await; - drop(guard3); + // let guard3 = exec_body_ar.read().await; + // (guard3)(parent_params).await; + // drop(guard3); + + // [ ] May need to do a blocking async of this? + exec_body_ar(parent_params); } @@ -1343,6 +1379,7 @@ impl Routine { { let mut self_lock = self_rw.write().await; self_lock.internal_signal = RoutineSignal::Stopping; + drop(self_lock); } @@ -1358,7 +1395,7 @@ impl Routine { "Routine > stop() > {:?}", self_lock.module )), - Some(&self_lock.parent_params.msg), + Some(&self_lock.parent_params.read().await.msg), ); Log::flush(); @@ -1403,6 +1440,7 @@ impl Routine { { let mut lock_mut = self_rw.write().await; lock_mut.internal_signal = RoutineSignal::Stopped; + drop(lock_mut); } } @@ -1419,7 +1457,7 @@ impl Routine { "Routine > cancel() > {:?}", self_lock.module )), - Some(&self_lock.parent_params.msg), + Some(&self_lock.parent_params.read().await.msg), ); Log::flush(); @@ -1459,9 +1497,11 @@ impl Routine { { let mut self_lock = self_rw.write().await; self_lock.cancel().await?; + drop(self_lock); } else { let mut self_lock = self_rw.write().await; self_lock.stop().await?; + drop(self_lock); } Routine::start(self_rw.clone()).await?; @@ -1478,7 +1518,7 @@ impl Routine { "Routine > restart() > {:?}", self_lock.module )), - Some(&self_lock.parent_params.msg), + Some(&self_lock.parent_params.read().await.msg), ); Log::flush(); @@ -1512,7 +1552,7 @@ impl Routine { "Routine > restart() > {:?}", self_lock.module )), - Some(&self_lock.parent_params.msg), + Some(&self_lock.parent_params.read().await.msg), ); Log::flush(); @@ -1539,6 +1579,7 @@ impl Routine { { let mut self_lock = self_rw.write().await; self_lock.routine_attr = routine_attr; + drop(self_lock); } // let self_rw = Arc::new(RwLock::new(self)); @@ -1555,7 +1596,7 @@ impl Routine { "Routine > restart() > {:?}", self_lock.module )), - Some(&self_lock.parent_params.msg), + Some(&self_lock.parent_params.read().await.msg), ); Log::flush(); diff --git a/src/custom/experimental/experiment003.rs b/src/custom/experimental/experiment003.rs index 774e24b..6b5a3de 100644 --- a/src/custom/experimental/experiment003.rs +++ b/src/custom/experimental/experiment003.rs @@ -142,19 +142,24 @@ async fn countdown_chnl_v1(params : ExecBodyParams) { // let parentmodule = params.get_parent_module().await; let module = params.get_module().await; // let channel = params.get_channel().await; - let channel = params.get_channel().await; + // let channel = params.get_channel().await; + let channel = params.get_channel(); let routine_attr = vec![ // RoutineAttr::RunOnce RoutineAttr::MaxIterations(5), RoutineAttr::LoopDuration(Duration::from_secs(1)) ]; // let exec_body = actions_util::asyncbox(rtestbody); - let exec_body = actions_util::asyncbox(innertester); // <-- 03.27 - when below is uncommented, this is throwing an issue + // let exec_body = actions_util::asyncbox(innertester); // <-- 03.27 - when below is uncommented, this is throwing an issue + let exec_body = innertester; - async fn innertester(params : ExecBodyParams) { + // async fn innertester(params : ExecBodyParams) { + fn innertester(params : Arc>) { { - let curract_guard = params.curr_act.read().await; + // let curract_guard = params.curr_act.read().await; + let paramguard1 = params.blocking_read(); + let curract_guard = paramguard1.curr_act.blocking_read(); // let logmsg_botact = match *params.curr_act.read().await { @@ -169,16 +174,19 @@ async fn countdown_chnl_v1(params : ExecBodyParams) { botlog::trace( format!("Params > Curr_act type : {:?}", logmsg_botact).as_str(), Some("Experiments003 > countdown_chnl()".to_string()), - Some(¶ms.msg), + Some(¶ms.blocking_read().msg), ); Log::flush(); } { - let bot = Arc::clone(¶ms.bot); - let botlock = bot.read().await; + let bot = Arc::clone(¶ms.blocking_read().bot); + // let botlock = bot.read().await; + let botlock = bot.blocking_read(); - let curract_guard = params.curr_act.write().await; + // let curract_guard = params.curr_act.write().await; + let paramguard1 = params.blocking_read(); + let curract_guard = paramguard1.curr_act.blocking_write(); // let routine_lock = arr.write().await; @@ -208,7 +216,8 @@ async fn countdown_chnl_v1(params : ExecBodyParams) { // } { - let routine_lock = arr.write().await; + // let routine_lock = arr.write().await; + let routine_lock = arr.blocking_write(); let a = routine_lock.remaining_iterations; println!("remaining iterations : {:?}", a); } @@ -248,7 +257,7 @@ async fn countdown_chnl_v1(params : ExecBodyParams) { botlog::trace( format!("Picked a channel: {:?}", chosen_channel).as_str(), Some("Experiments003 > countdown_chnl()".to_string()), - Some(¶ms.msg), + Some(¶ms.blocking_read().msg), ); Log::flush(); @@ -280,8 +289,9 @@ async fn countdown_chnl_v1(params : ExecBodyParams) { module, channel.unwrap(), routine_attr, - Arc::new(RwLock::new(exec_body)), - params.clone() + // Arc::new(RwLock::new(exec_body)), + exec_body, + Arc::new(RwLock::new(params.clone())), ).await { let newr_ar = newr.clone(); // [ ] start the routine @@ -358,25 +368,47 @@ async fn test3_body(params : ExecBodyParams) { // [x] Get the module from params + + let params_ar = Arc::new(RwLock::new(params)); + // let parentmodule = params.get_parent_module().await; - let module = params.get_module().await; + let module = params_ar.read().await.get_module().await; // let channel = params.get_channel().await; - let channel = params.get_channel().await; + // let channel = params.get_channel().await; + // let channel = params.get_channel(); let routine_attr = vec![ RoutineAttr::RunOnce ]; // let exec_body = actions_util::asyncbox(rtestbody); - let exec_body = actions_util::asyncbox(rtestbody); // <-- 03.27 - when below is uncommented, this is throwing an issue + // let exec_body = actions_util::asyncbox(rtestbody); // <-- 03.27 - when below is uncommented, this is throwing an issue + // let channel = params.get_channel(); + let channel_task_grabber = tokio::task::spawn_blocking( move || { + let params_clone = params_ar.clone(); + let channel = params_clone.blocking_read().get_channel(); + drop(params_clone); + (channel,params_ar) + }); + + let (channel,params_ar) = channel_task_grabber.await.unwrap(); + + + + + + let exec_body = rtestbody; // let parent_params = params.clone(); // let params_clone = params.clone(); - async fn rtestbody(params : ExecBodyParams) { + // async fn rtestbody(params : ExecBodyParams) { + fn rtestbody(params : Arc>) { - let guard1 = params.curr_act.read().await; + // let guard1 = params.curr_act.read().await; + let paramguard1 = params.blocking_read(); + let guard1 = paramguard1.curr_act.blocking_read(); { let logmsg_botact = match *guard1 { BotAction::C(_) => "command", @@ -387,7 +419,7 @@ async fn test3_body(params : ExecBodyParams) { botlog::trace( format!("Params > Curr_act type : {:?}", logmsg_botact).as_str(), Some("Experiments003 > test3 command body".to_string()), - Some(¶ms.msg), + Some(¶ms.blocking_read().msg), ); Log::flush(); } @@ -403,7 +435,7 @@ async fn test3_body(params : ExecBodyParams) { botlog::trace( format!("Params > Curr_act type : {:?}", logmsg_botact).as_str(), Some("Experiments003 > test3 command body".to_string()), - Some(¶ms.msg), + Some(¶ms.blocking_read().msg), ); Log::flush(); } @@ -439,7 +471,8 @@ async fn test3_body(params : ExecBodyParams) { // } ; // let chnl = params.get_channel().await; - let chnl = params.get_channel().await; + // let chnl = params.get_channel().await; + let chnl = params.blocking_read().get_channel(); dbg!("Custom > within Child Custom fn - after GetChannel"); println!("{:?}",chnl); @@ -461,14 +494,14 @@ async fn test3_body(params : ExecBodyParams) { } - + let params_clone = params_ar.clone(); botlog::debug( format!("RTESTBODY : module - {:?} ; channel - {:?}", module,channel ).as_str(), Some("experiment003 > test3_body".to_string()), - Some(¶ms.msg), + Some(¶ms_clone.read().await.msg), ); @@ -478,8 +511,9 @@ async fn test3_body(params : ExecBodyParams) { module, channel.unwrap(), routine_attr, - Arc::new(RwLock::new(exec_body)), - params.clone() + // Arc::new(RwLock::new(exec_body)), + exec_body, + Arc::new(RwLock::new(params_clone.read().await.clone())) ).await; @@ -520,12 +554,12 @@ async fn test3_body(params : ExecBodyParams) { rsltstr ).as_str(), Some("experiment003 > test3_body".to_string()), - Some(¶ms.msg), + Some(&(params_ar.clone()).read().await.msg), ); Log::flush(); - let bot = Arc::clone(¶ms.bot); + let bot = Arc::clone(¶ms_ar.read().await.bot); let botlock = bot.read().await; @@ -534,9 +568,9 @@ async fn test3_body(params : ExecBodyParams) { .botmgrs .chat .say_in_reply_to( - ¶ms.msg, + ¶ms_ar.read().await.msg, format!("Routine Result : {:?}",rsltstr), - params.clone() + params_clone.read().await.clone() ).await; // [x] Will not be handling JoinHandles here . If immediate abort() handling is required, below is an example that works diff --git a/src/main.rs b/src/main.rs index 866fc38..3a797a4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,7 +22,14 @@ pub async fn main() { Log::set_retention_days(2); // Log::set_level(Level::Notice); - + // fn innerbody() -> i64 { + // println!("hello"); + // 64 + // } + + // let exec_body:fn() -> i64 = innerbody; + + -- 2.46.0 From e711c6454dd29456103d9e3ec6a3c2707cc5691f Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Sun, 31 Mar 2024 20:09:00 -0400 Subject: [PATCH 09/10] ExecBodyParams curr_act --- src/core/bot_actions.rs | 14 +++-- src/core/botinstance.rs | 10 ++-- src/core/botmodules.rs | 65 ++++++++++++++++------ src/custom/experimental/experiment003.rs | 70 +++++++++++++++++------- 4 files changed, 112 insertions(+), 47 deletions(-) diff --git a/src/core/bot_actions.rs b/src/core/bot_actions.rs index 7775beb..4a07d9e 100644 --- a/src/core/bot_actions.rs +++ b/src/core/bot_actions.rs @@ -17,7 +17,13 @@ pub struct ExecBodyParams { pub bot : BotAR, pub msg : PrivmsgMessage, pub parent_act : Option , - pub curr_act : ActAR , + pub curr_act : Option , +} + +#[derive(Debug,Eq,PartialEq,Hash)] +pub enum ParamLevel { + Parent, + Current, } @@ -27,8 +33,8 @@ impl ExecBodyParams { // pub async fn get_parent_module(&self) -> BotModule { pub async fn get_module(&self) -> BotModule { - let curr_act = Arc::clone(&self.curr_act); - let parent_act_lock = curr_act.read().await; + let curr_acta = Arc::clone(&(self.curr_act.clone().unwrap())); + let parent_act_lock = curr_acta.read().await; let act = &(*parent_act_lock); match act { BotAction::C(c) => { @@ -61,7 +67,7 @@ impl ExecBodyParams { dbg!(">> BotInstanceAR - RwLock from botinstance.rs::150:28 - current_readers = 2"); - let curr_act = Arc::clone(&self.curr_act); + let curr_act = Arc::clone(&self.curr_act.clone().unwrap()); // let curr_act_lock = curr_act.read().await; // Note : The below `curr_act.blocking_read()` is not possible. I get the following diff --git a/src/core/botinstance.rs b/src/core/botinstance.rs index 2c06cea..d17f8c8 100644 --- a/src/core/botinstance.rs +++ b/src/core/botinstance.rs @@ -406,7 +406,7 @@ impl BotInstance { bot : Arc::clone(&bot), msg : (*msg).clone(), parent_act : None, - curr_act : Arc::clone(&act_clone), + curr_act : Some(Arc::clone(&act_clone)), }; // When sending a BotMsgTypeNotif, send_botmsg does Roles related validation as required @@ -464,7 +464,7 @@ impl BotInstance { bot : Arc::clone(&bot), msg : (*msg).clone(), parent_act : None, - curr_act : Arc::clone(&act_clone), + curr_act : Some(Arc::clone(&act_clone)), }; @@ -495,7 +495,7 @@ impl BotInstance { bot : Arc::clone(&bot), msg : (*msg).clone(), parent_act : None, - curr_act : Arc::clone(&act_clone), + curr_act : Some(Arc::clone(&act_clone)), }; @@ -521,7 +521,7 @@ impl BotInstance { bot : a, msg : msg.clone() , parent_act : None, - curr_act : Arc::clone(&act_clone), + curr_act : Some(Arc::clone(&act_clone)), }).await; botlog::trace( @@ -570,7 +570,7 @@ impl BotInstance { bot : a, msg : msg.clone() , parent_act : None, - curr_act : Arc::clone(&act_clone), + curr_act : Some(Arc::clone(&act_clone)), } ).await; } diff --git a/src/core/botmodules.rs b/src/core/botmodules.rs index 5bc9f0a..fcc731e 100644 --- a/src/core/botmodules.rs +++ b/src/core/botmodules.rs @@ -57,6 +57,7 @@ use crate::core::bot_actions; use std::hash::{Hash, Hasher}; use super::bot_actions::ActAR; +use super::bot_actions::ParamLevel; use super::bot_actions::RoutineAR; use super::identity::ChatBadge; @@ -640,15 +641,18 @@ pub enum RoutineSignal { NotStarted, } +pub type ExecBodyParamsAr = Arc>; + pub struct Routine { pub name : String , pub module : BotModule , // from() can determine this if passed parents_params pub channel : Channel , // Requiring some channel context // exec_body: Arc>, // exec_body : fn(ExecBodyParams), - exec_body : fn(Arc>), + exec_body : fn(ExecBodyParamsAr), // pub parent_params : ExecBodyParams , - pub parent_params : Arc> , + // pub parent_params : Arc> , + pub params : HashMap, pub join_handle : Option>>> , start_time : Option> , pub complete_iterations : i64 , @@ -665,7 +669,7 @@ impl Debug for Routine { write!(f, "{:?}", self.name)?; write!(f, "{:?}", self.module)?; write!(f, "{:?}", self.channel)?; - write!(f, "{:?}", self.parent_params)?; + write!(f, "{:?}", self.params)?; write!(f, "{:?}", self.join_handle)?; write!(f, "{:?}", self.start_time)?; write!(f, "{:?}", self.complete_iterations)?; @@ -911,12 +915,27 @@ impl Routine { Routine::validate_attr(&routine_attr).await?; + let mut params = HashMap::new(); + params.insert(ParamLevel::Parent,parent_params.clone()); + + let pparam_clone = parent_params.clone(); + let parent_guard = pparam_clone.read().await; + let curr_params = ExecBodyParams { + bot : parent_guard.bot.clone(), + msg : parent_guard.msg.clone(), + parent_act : parent_guard.curr_act.clone() , + curr_act : None, + }; + + params.insert(ParamLevel::Current,Arc::new(RwLock::new(curr_params))); + let routine_ar = Arc::new(RwLock::new(Routine { name , module , channel , exec_body , - parent_params , + // parent_params , + params, join_handle : None , start_time : None , complete_iterations : 0 , @@ -933,6 +952,8 @@ impl Routine { // 2. Update the current self_act_ar mut_lock.self_act_ar = Some(Arc::new(RwLock::new(BotAction::R(routine_ar.clone())))); + mut_lock.params.get(&ParamLevel::Current).unwrap().write().await.curr_act = Some(Arc::new(RwLock::new(BotAction::R(routine_ar.clone())))); + Ok(routine_ar.clone()) // return Ok(Arc::new(RwLock::new(Routine { @@ -1018,7 +1039,7 @@ impl Routine { Some(format!( "Routine > start() > (In Tokio Spawn)", )), - Some(&trg_routine_ar.read().await.parent_params.read().await.msg), + Some(&trg_routine_ar.read().await.params.get(&ParamLevel::Parent).unwrap().read().await.msg), ); Log::flush(); @@ -1031,7 +1052,7 @@ impl Routine { Some(format!( "Routine > start() > (In Tokio Spawn)", )), - Some(&trg_routine_ar.read().await.parent_params.read().await.msg), + Some(&trg_routine_ar.read().await.params.get(&ParamLevel::Parent).unwrap().read().await.msg), ); Log::flush(); @@ -1114,7 +1135,7 @@ impl Routine { "Routine > start() > (In Tokio Spawn) > {:?}", trg_routine_ar.read().await.module )), - Some(&trg_routine_ar.read().await.parent_params.read().await.msg), + Some(&trg_routine_ar.read().await.params.get(&ParamLevel::Parent).unwrap().read().await.msg), ); if let Some(dur) = delayduration { @@ -1223,7 +1244,7 @@ impl Routine { "Routine > start() > (In Tokio Spawn) > {:?}", trg_routine_ar.read().await.module )), - Some(&trg_routine_ar.read().await.parent_params.read().await.msg), + Some(&trg_routine_ar.read().await.params.get(&ParamLevel::Parent).unwrap().read().await.msg), ); botlog::trace( @@ -1238,7 +1259,7 @@ impl Routine { "Routine > start() > (In Tokio Spawn) > {:?}", trg_routine_ar.read().await.module )), - Some(&trg_routine_ar.read().await.parent_params.read().await.msg), + Some(&trg_routine_ar.read().await.params.get(&ParamLevel::Parent).unwrap().read().await.msg), ); Log::flush(); @@ -1311,14 +1332,22 @@ impl Routine { // self_ar.read().await.parent_params.clone() // ).await; - let parent_params = { + // let parent_params = { + // let guard1 = self_ar.blocking_read(); + + // let parent_params = guard1.params.get(&ParamLevel::Parent).unwrap().clone(); + // drop(guard1); + // parent_params + // }; + let curr_params = { let guard1 = self_ar.blocking_read(); - let parent_params = guard1.parent_params.clone(); + let curr_params = guard1.params.get(&ParamLevel::Current).unwrap().clone(); drop(guard1); - parent_params + curr_params }; + dbg!("Core > Guarding and will Execute Child Execution Body"); dbg!(">> BotActionAR - RwLock from botmodules.rs::929:46 - current_readers = 0 "); dbg!(">> RoutineAR - RwLock from botmodules.rs::1261:32 - current_readers = Not Listed"); @@ -1352,7 +1381,7 @@ impl Routine { // drop(guard3); // [ ] May need to do a blocking async of this? - exec_body_ar(parent_params); + exec_body_ar(curr_params); } @@ -1395,7 +1424,7 @@ impl Routine { "Routine > stop() > {:?}", self_lock.module )), - Some(&self_lock.parent_params.read().await.msg), + Some(&self_lock.params.get(&ParamLevel::Parent).unwrap().read().await.msg), ); Log::flush(); @@ -1457,7 +1486,7 @@ impl Routine { "Routine > cancel() > {:?}", self_lock.module )), - Some(&self_lock.parent_params.read().await.msg), + Some(&self_lock.params.get(&ParamLevel::Parent).unwrap().read().await.msg), ); Log::flush(); @@ -1518,7 +1547,7 @@ impl Routine { "Routine > restart() > {:?}", self_lock.module )), - Some(&self_lock.parent_params.read().await.msg), + Some(&self_lock.params.get(&ParamLevel::Parent).unwrap().read().await.msg), ); Log::flush(); @@ -1552,7 +1581,7 @@ impl Routine { "Routine > restart() > {:?}", self_lock.module )), - Some(&self_lock.parent_params.read().await.msg), + Some(&self_lock.params.get(&ParamLevel::Parent).unwrap().read().await.msg), ); Log::flush(); @@ -1596,7 +1625,7 @@ impl Routine { "Routine > restart() > {:?}", self_lock.module )), - Some(&self_lock.parent_params.read().await.msg), + Some(&self_lock.params.get(&ParamLevel::Parent).unwrap().read().await.msg), ); Log::flush(); diff --git a/src/custom/experimental/experiment003.rs b/src/custom/experimental/experiment003.rs index 6b5a3de..45e637b 100644 --- a/src/custom/experimental/experiment003.rs +++ b/src/custom/experimental/experiment003.rs @@ -139,11 +139,23 @@ async fn countdown_chnl_v1(params : ExecBodyParams) { // [ ] 1. Create a Routine & start a routine + let params_ar = Arc::new(RwLock::new(params)); + // let parentmodule = params.get_parent_module().await; - let module = params.get_module().await; + let module = params_ar.read().await.get_module().await; // let channel = params.get_channel().await; // let channel = params.get_channel().await; - let channel = params.get_channel(); + // let channel = params.get_channel(); + + let channel_task_grabber = tokio::task::spawn_blocking( move || { + let params_clone = params_ar.clone(); + let channel = params_clone.blocking_read().get_channel(); + drop(params_clone); + (channel,params_ar) + }); + + let (channel,params_ar) = channel_task_grabber.await.unwrap(); + let routine_attr = vec![ // RoutineAttr::RunOnce RoutineAttr::MaxIterations(5), @@ -159,7 +171,8 @@ async fn countdown_chnl_v1(params : ExecBodyParams) { { // let curract_guard = params.curr_act.read().await; let paramguard1 = params.blocking_read(); - let curract_guard = paramguard1.curr_act.blocking_read(); + let curract = paramguard1.curr_act.clone().unwrap(); + let curract_guard = curract.blocking_read(); // let logmsg_botact = match *params.curr_act.read().await { @@ -186,7 +199,8 @@ async fn countdown_chnl_v1(params : ExecBodyParams) { // let curract_guard = params.curr_act.write().await; let paramguard1 = params.blocking_read(); - let curract_guard = paramguard1.curr_act.blocking_write(); + let curract = paramguard1.curr_act.clone().unwrap(); + let curract_guard = curract.blocking_write(); // let routine_lock = arr.write().await; @@ -215,11 +229,13 @@ async fn countdown_chnl_v1(params : ExecBodyParams) { // println!("Remaining iterations > {}",a) // } + let iterleft; { // let routine_lock = arr.write().await; - let routine_lock = arr.blocking_write(); - let a = routine_lock.remaining_iterations; - println!("remaining iterations : {:?}", a); + // let routine_lock = arr.blocking_write(); + let routine_lock = arr.blocking_read(); + iterleft = routine_lock.remaining_iterations.unwrap_or(0); + println!("remaining iterations : {:?}", iterleft); } botlog::trace( @@ -254,26 +270,39 @@ async fn countdown_chnl_v1(params : ExecBodyParams) { let chosen_channel = pick_a_channel(joinedchannels); + dbg!("SUCCESS", chosen_channel.clone()); + botlog::trace( format!("Picked a channel: {:?}", chosen_channel).as_str(), Some("Experiments003 > countdown_chnl()".to_string()), Some(¶ms.blocking_read().msg), ); Log::flush(); + + // let a = || { - // let outmsg = if iterleft == 1 { + // let chosen_channel_ar = Arc::new(RwLock::new(chosen_channel)); + + // let params_clone = params.clone(); + // let bot = Arc::clone(¶ms.blocking_read().bot); + + + // dbg!("in chat async function"); + + // let botlock = bot.blocking_read(); + // let channel_ar_clone = chosen_channel_ar.clone(); + + // let outmsg = if iterleft <= 1 { // format!("{} I love you uwu~",iterleft) // } else { format!("{}",iterleft) }; // botlock.botmgrs.chat // .say( - // // joinedchannels.choose(&mut rng).unwrap().0.clone(), - // chosen_channel.0.clone(), + // channel_ar_clone.read().await.0.clone(), // outmsg, - // params.clone() - - - // ).await; + // params_clone.read().await.clone() + // ).await; + } } @@ -291,7 +320,7 @@ async fn countdown_chnl_v1(params : ExecBodyParams) { routine_attr, // Arc::new(RwLock::new(exec_body)), exec_body, - Arc::new(RwLock::new(params.clone())), + Arc::new(RwLock::new(params_ar.clone().read().await.clone())), ).await { let newr_ar = newr.clone(); // [ ] start the routine @@ -301,13 +330,13 @@ async fn countdown_chnl_v1(params : ExecBodyParams) { botlog::debug( "Successfully started", Some("experiment003 > countdown_chnl()".to_string()), - Some(¶ms.msg), + Some(¶ms_ar.read().await.msg), ); Log::flush(); - let bot = Arc::clone(¶ms.bot); + let bot = Arc::clone(¶ms_ar.read().await.bot); let botlock = bot.read().await; @@ -316,9 +345,9 @@ async fn countdown_chnl_v1(params : ExecBodyParams) { .botmgrs .chat .say_in_reply_to( - ¶ms.msg, + ¶ms_ar.read().await.msg, "Started Routine!".to_string(), - params.clone() + params_ar.read().await.clone() ).await; // let jhandle = newr.clone().read().await.join_handle.clone().unwrap(); @@ -408,7 +437,8 @@ async fn test3_body(params : ExecBodyParams) { // let guard1 = params.curr_act.read().await; let paramguard1 = params.blocking_read(); - let guard1 = paramguard1.curr_act.blocking_read(); + let curract = paramguard1.curr_act.clone().unwrap(); + let guard1 = curract.blocking_read(); { let logmsg_botact = match *guard1 { BotAction::C(_) => "command", -- 2.46.0 From 8ed672fb3a3e452d5f0299bc44dec11a8cfe351d Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Sun, 31 Mar 2024 20:12:49 -0400 Subject: [PATCH 10/10] comment issue with fix --- src/custom/experimental/experiment003.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/custom/experimental/experiment003.rs b/src/custom/experimental/experiment003.rs index 45e637b..ed1c6ba 100644 --- a/src/custom/experimental/experiment003.rs +++ b/src/custom/experimental/experiment003.rs @@ -279,6 +279,11 @@ async fn countdown_chnl_v1(params : ExecBodyParams) { ); Log::flush(); + // [ ] !! ISSUE : With this fix though, the custom fn is no longer + // async. This is an issue because chat module is async + // - There should be no need to change chat , as async allows + // us to multitask with messages + // let a = || { // let chosen_channel_ar = Arc::new(RwLock::new(chosen_channel)); -- 2.46.0