WIP: Basic Routine Functionality #40

Draft
modulatingforce wants to merge 23 commits from routines-functionality into master
2 changed files with 87 additions and 44 deletions
Showing only changes of commit b5e95668a5 - Show all commits

View file

@ -1104,7 +1104,9 @@ impl Routine {
// [x] execution body
// trg_routine_ar.read().await.loopbody().await;
trg_routine_ar.write().await.loopbody().await;
{
trg_routine_ar.write().await.loopbody().await;
}
{ // [x] End of Loop iteration

View file

@ -152,34 +152,44 @@ async fn countdown_chnl_v1(params : ExecBodyParams) {
async fn innertester(params : ExecBodyParams) {
{
let curract_guard = params.curr_act.read().await;
let logmsg_botact = match *params.curr_act.read().await {
BotAction::C(_) => "command",
BotAction::R(_) => "routine",
BotAction::L(_) => "listener",
} ;
// let logmsg_botact = match *params.curr_act.read().await {
let logmsg_botact = match *curract_guard {
BotAction::C(_) => "command",
BotAction::R(_) => "routine",
BotAction::L(_) => "listener",
} ;
botlog::trace(
format!("Params > Curr_act type : {:?}", logmsg_botact).as_str(),
Some("Experiments003 > countdown_chnl()".to_string()),
Some(&params.msg),
);
Log::flush();
let bot = Arc::clone(&params.bot);
let botlock = bot.read().await;
if let BotAction::R(arr) = &*params.curr_act.read().await {
botlog::trace(
"Before loading remaining iterations",
format!("Params > Curr_act type : {:?}", logmsg_botact).as_str(),
Some("Experiments003 > countdown_chnl()".to_string()),
None,
Some(&params.msg),
);
Log::flush();
}
{
let bot = Arc::clone(&params.bot);
let botlock = bot.read().await;
let curract_guard = params.curr_act.write().await;
// let routine_lock = arr.write().await;
if let BotAction::R(arr) = &*curract_guard {
// if let BotAction::R(arr) = &*params.curr_act.read().await {
botlog::trace(
"Before loading remaining iterations",
Some("Experiments003 > countdown_chnl()".to_string()),
None,
);
Log::flush();
// let iterleft = arr.read().await.remaining_iterations.unwrap_or(0);
@ -197,10 +207,10 @@ async fn countdown_chnl_v1(params : ExecBodyParams) {
// }
{
let routine_lock = arr.write().await;
let a = routine_lock.remaining_iterations;
println!("remaining iterations : {:?}", a);
}
let routine_lock = arr.write().await;
let a = routine_lock.remaining_iterations;
println!("remaining iterations : {:?}", a);
}
botlog::trace(
"after loading remaining iterations",
@ -251,9 +261,12 @@ async fn countdown_chnl_v1(params : ExecBodyParams) {
// chosen_channel.0.clone(),
// outmsg,
// params.clone()
// ).await;
}
}
}
@ -361,27 +374,55 @@ async fn test3_body(params : ExecBodyParams) {
async fn rtestbody(params : ExecBodyParams) {
let logmsg_botact = match *params.curr_act.read().await {
BotAction::C(_) => "command",
BotAction::R(_) => "routine",
BotAction::L(_) => "listener",
} ;
let guard = params.curr_act.read().await;
{
let logmsg_botact = match *guard {
BotAction::C(_) => "command",
BotAction::R(_) => "routine",
BotAction::L(_) => "listener",
} ;
botlog::trace(
format!("Params > Curr_act type : {:?}", logmsg_botact).as_str(),
Some("Experiments003 > test3 command body".to_string()),
Some(&params.msg),
);
Log::flush();
botlog::trace(
format!("Params > Curr_act type : {:?}", logmsg_botact).as_str(),
Some("Experiments003 > test3 command body".to_string()),
Some(&params.msg),
);
Log::flush();
}
if let BotAction::R(arr) = &*params.curr_act.read().await {
for curriter in 0..5 {
println!("tester - Routine - Completed Iterations : {}",
arr.read().await.complete_iterations);
println!("tester - Custom Loop - Completed Iterations : {}",
curriter);
sleep(Duration::from_secs_f64(0.5)).await;
{
let logmsg_botact = match *guard {
BotAction::C(_) => "command 2",
BotAction::R(_) => "routine 2",
BotAction::L(_) => "listener 2",
} ;
botlog::trace(
format!("Params > Curr_act type : {:?}", logmsg_botact).as_str(),
Some("Experiments003 > test3 command body".to_string()),
Some(&params.msg),
);
Log::flush();
}
{
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
Review

ISSUE . The defined Routine's Custom Execution Body is being reached (so the custom fn is being triggered as expected); However, I believe at L413 where c.read().await.channel , it never goes beyond that point within the same Custom fn body

Even if the bot continues to be responsive (i.e., the main bot continues to run), the rest of the routine is not. I believe this is suggesting there's a lock with one of the objects we're introducing with this feature . In the above line, I believe the lock involves ExecBodyParam's curr_act value

**_ISSUE ._** The defined Routine's Custom Execution Body is being reached (so the custom `fn` is being triggered as expected); However, I believe at L413 where `c.read().await.channel` , it never goes beyond that point within the same Custom `fn` body Even if the bot continues to be responsive (i.e., the `main` bot continues to run), the rest of the routine is not. I *believe* this is suggesting there's a lock with one of the objects we're introducing with this feature . In the above line, I believe the lock involves `ExecBodyParam`'s `curr_act` value
// if let BotAction::R(arr) = &*params.curr_act.read().await {
// for curriter in 0..5 {
// println!("tester - Routine - Completed Iterations : {}",
// arr.read().await.complete_iterations);
// println!("tester - Custom Loop - Completed Iterations : {}",
// curriter);
// sleep(Duration::from_secs_f64(0.5)).await;
// }
// }
}
}