ExecBody & routine addl references
This commit is contained in:
parent
ca9361cc93
commit
2a1a7f8503
4 changed files with 74 additions and 26 deletions
|
@ -16,7 +16,7 @@ pub type RoutineAR = Arc<RwLock<Routine>>;
|
||||||
pub struct ExecBodyParams {
|
pub struct ExecBodyParams {
|
||||||
pub bot : BotAR,
|
pub bot : BotAR,
|
||||||
pub msg : PrivmsgMessage,
|
pub msg : PrivmsgMessage,
|
||||||
// pub parent_act : ActAR ,
|
pub parent_act : Option<ActAR> ,
|
||||||
pub curr_act : ActAR ,
|
pub curr_act : ActAR ,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -404,6 +404,7 @@ impl BotInstance {
|
||||||
let params = ExecBodyParams {
|
let params = ExecBodyParams {
|
||||||
bot : Arc::clone(&bot),
|
bot : Arc::clone(&bot),
|
||||||
msg : (*msg).clone(),
|
msg : (*msg).clone(),
|
||||||
|
parent_act : None,
|
||||||
curr_act : Arc::clone(&act_clone),
|
curr_act : Arc::clone(&act_clone),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -461,6 +462,7 @@ impl BotInstance {
|
||||||
let params = ExecBodyParams {
|
let params = ExecBodyParams {
|
||||||
bot : Arc::clone(&bot),
|
bot : Arc::clone(&bot),
|
||||||
msg : (*msg).clone(),
|
msg : (*msg).clone(),
|
||||||
|
parent_act : None,
|
||||||
curr_act : Arc::clone(&act_clone),
|
curr_act : Arc::clone(&act_clone),
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -491,6 +493,7 @@ impl BotInstance {
|
||||||
let params = ExecBodyParams {
|
let params = ExecBodyParams {
|
||||||
bot : Arc::clone(&bot),
|
bot : Arc::clone(&bot),
|
||||||
msg : (*msg).clone(),
|
msg : (*msg).clone(),
|
||||||
|
parent_act : None,
|
||||||
curr_act : Arc::clone(&act_clone),
|
curr_act : Arc::clone(&act_clone),
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -516,6 +519,7 @@ impl BotInstance {
|
||||||
c.execute(ExecBodyParams {
|
c.execute(ExecBodyParams {
|
||||||
bot : a,
|
bot : a,
|
||||||
msg : msg.clone() ,
|
msg : msg.clone() ,
|
||||||
|
parent_act : None,
|
||||||
curr_act : Arc::clone(&act_clone),
|
curr_act : Arc::clone(&act_clone),
|
||||||
}).await;
|
}).await;
|
||||||
|
|
||||||
|
@ -564,6 +568,7 @@ impl BotInstance {
|
||||||
l.execute(ExecBodyParams {
|
l.execute(ExecBodyParams {
|
||||||
bot : a,
|
bot : a,
|
||||||
msg : msg.clone() ,
|
msg : msg.clone() ,
|
||||||
|
parent_act : None,
|
||||||
curr_act : Arc::clone(&act_clone),
|
curr_act : Arc::clone(&act_clone),
|
||||||
} ).await;
|
} ).await;
|
||||||
}
|
}
|
||||||
|
|
|
@ -637,12 +637,39 @@ pub struct Routine {
|
||||||
remaining_iterations : Option<i64> ,
|
remaining_iterations : Option<i64> ,
|
||||||
routine_attr : Vec<RoutineAttr> ,
|
routine_attr : Vec<RoutineAttr> ,
|
||||||
pub internal_signal : RoutineSignal ,
|
pub internal_signal : RoutineSignal ,
|
||||||
|
pub self_routine_ar : Option<RoutineAR> ,
|
||||||
|
pub self_act_ar : Option<ActAR> ,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl Routine {
|
impl Routine {
|
||||||
|
|
||||||
|
|
||||||
|
// pub fn set
|
||||||
|
// pub async fn refresh_self_ref(self) {
|
||||||
|
pub async fn refresh_routine_internal(routine_ar : RoutineAR)
|
||||||
|
{
|
||||||
|
|
||||||
|
/*
|
||||||
|
Execute after the Routine is constructed
|
||||||
|
- If not, a start() will also call this
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
// 1. Update the self reference to itself
|
||||||
|
|
||||||
|
let mut mut_lock = routine_ar.write().await;
|
||||||
|
mut_lock.self_routine_ar = Some(routine_ar.clone());
|
||||||
|
|
||||||
|
// 2. Update the current self_act_ar
|
||||||
|
mut_lock.self_act_ar = Some(Arc::new(RwLock::new(BotAction::R(routine_ar.clone()))));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
pub async fn validate_attr(routine_attr : &Vec<RoutineAttr>)
|
pub async fn validate_attr(routine_attr : &Vec<RoutineAttr>)
|
||||||
-> Result<String,String>
|
-> Result<String,String>
|
||||||
|
@ -819,6 +846,8 @@ impl Routine {
|
||||||
remaining_iterations : None ,
|
remaining_iterations : None ,
|
||||||
routine_attr : routine_attr ,
|
routine_attr : routine_attr ,
|
||||||
internal_signal : RoutineSignal::NotStarted ,
|
internal_signal : RoutineSignal::NotStarted ,
|
||||||
|
self_routine_ar : None ,
|
||||||
|
self_act_ar : None ,
|
||||||
}))) ;
|
}))) ;
|
||||||
|
|
||||||
|
|
||||||
|
@ -831,6 +860,10 @@ impl Routine {
|
||||||
// [ ] => 03.27 - REVIEW FOR COMPLETION
|
// [ ] => 03.27 - REVIEW FOR COMPLETION
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
// [x] Prep by updating it's own self reference
|
||||||
|
Routine::refresh_routine_internal(trg_routine_ar.clone()).await;
|
||||||
|
|
||||||
// [x] Asyncio Spawn likely around here
|
// [x] Asyncio Spawn likely around here
|
||||||
// [x] & Assigns self.join_handle
|
// [x] & Assigns self.join_handle
|
||||||
|
|
||||||
|
@ -1005,7 +1038,8 @@ impl Routine {
|
||||||
|
|
||||||
|
|
||||||
// [x] execution body
|
// [x] execution body
|
||||||
trg_routine_ar.read().await.loopbody().await;
|
// trg_routine_ar.read().await.loopbody().await;
|
||||||
|
trg_routine_ar.write().await.loopbody().await;
|
||||||
|
|
||||||
|
|
||||||
{ // [x] End of Loop iteration
|
{ // [x] End of Loop iteration
|
||||||
|
@ -1100,7 +1134,7 @@ impl Routine {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn loopbody(&self)
|
async fn loopbody(&mut self)
|
||||||
// [x] => 03.27 - COMPLETED
|
// [x] => 03.27 - COMPLETED
|
||||||
{
|
{
|
||||||
botlog::trace(
|
botlog::trace(
|
||||||
|
@ -1113,9 +1147,22 @@ impl Routine {
|
||||||
|
|
||||||
Log::flush();
|
Log::flush();
|
||||||
|
|
||||||
(self.exec_body)(
|
let self_ar = Arc::new(RwLock::new(self));
|
||||||
self.parent_params.clone()
|
|
||||||
|
{
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
(self_ar.read().await.exec_body)(
|
||||||
|
self_ar.read().await.parent_params.clone()
|
||||||
).await;
|
).await;
|
||||||
|
|
||||||
|
// (self.exec_body)(
|
||||||
|
// self.parent_params.clone()
|
||||||
|
// ).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn stop(&mut self) -> Result<String,String>
|
pub async fn stop(&mut self) -> Result<String,String>
|
||||||
|
|
|
@ -141,28 +141,24 @@ async fn test3_body(params : ExecBodyParams) {
|
||||||
|
|
||||||
if let Ok(newr) = a {
|
if let Ok(newr) = a {
|
||||||
|
|
||||||
|
// NOTE : The below is a "Playing aound" feature
|
||||||
|
// In the below, we're unnecessarily adjusting the ExecBodyParams of the parent
|
||||||
|
|
||||||
|
// To get the reference to the Routine or the BotAction there are now refernces to itself
|
||||||
|
|
||||||
// [ ] before execute , be sure to adjust curr_act
|
// [ ] before execute , be sure to adjust curr_act
|
||||||
|
|
||||||
// let mut params_mut = params.clone();
|
// let mut params_mut = params;
|
||||||
let mut params_mut = params;
|
|
||||||
// let newr_ar = Arc::new(RwLock::new(newr));
|
|
||||||
let newr_ar = newr.clone();
|
let newr_ar = newr.clone();
|
||||||
|
|
||||||
params_mut.curr_act = Arc::new(RwLock::new(
|
// params_mut.curr_act = Arc::new(RwLock::new(
|
||||||
BotAction::R(newr_ar.clone())
|
// BotAction::R(newr_ar.clone())
|
||||||
));
|
// ));
|
||||||
|
|
||||||
// let a = newr_ar.read().await;
|
|
||||||
// let rslt = (&*a).start().await;
|
|
||||||
|
|
||||||
// let mut newr_lock = newr_ar.write().await;
|
|
||||||
|
|
||||||
// let rslt = newr_ar.write().await.start().await;
|
|
||||||
|
|
||||||
|
|
||||||
{
|
// {
|
||||||
newr_ar.write().await.parent_params = params_mut.clone();
|
// newr_ar.write().await.parent_params = params_mut.clone();
|
||||||
}
|
// }
|
||||||
|
|
||||||
let rslt = Routine::start(newr_ar.clone()).await;
|
let rslt = Routine::start(newr_ar.clone()).await;
|
||||||
|
|
||||||
|
@ -179,12 +175,12 @@ async fn test3_body(params : ExecBodyParams) {
|
||||||
rsltstr
|
rsltstr
|
||||||
).as_str(),
|
).as_str(),
|
||||||
Some("experiment003 > test3_body".to_string()),
|
Some("experiment003 > test3_body".to_string()),
|
||||||
Some(¶ms_mut.msg),
|
Some(¶ms.msg),
|
||||||
);
|
);
|
||||||
|
|
||||||
Log::flush();
|
Log::flush();
|
||||||
|
|
||||||
let bot = Arc::clone(¶ms_mut.bot);
|
let bot = Arc::clone(¶ms.bot);
|
||||||
|
|
||||||
let botlock = bot.read().await;
|
let botlock = bot.read().await;
|
||||||
|
|
||||||
|
@ -193,9 +189,9 @@ async fn test3_body(params : ExecBodyParams) {
|
||||||
.botmgrs
|
.botmgrs
|
||||||
.chat
|
.chat
|
||||||
.say_in_reply_to(
|
.say_in_reply_to(
|
||||||
¶ms_mut.msg,
|
¶ms.msg,
|
||||||
format!("Routine Result : {:?}",rsltstr),
|
format!("Routine Result : {:?}",rsltstr),
|
||||||
params_mut.clone()
|
params.clone()
|
||||||
).await;
|
).await;
|
||||||
|
|
||||||
// [x] Will not be handling JoinHandles here . If immediate abort() handling is required, below is an example that works
|
// [x] Will not be handling JoinHandles here . If immediate abort() handling is required, below is an example that works
|
||||||
|
|
Loading…
Reference in a new issue