This commit is contained in:
ModulatingForce 2024-03-27 18:29:14 -04:00
parent 537c3565a2
commit 60fae25419

View file

@ -631,8 +631,91 @@ pub struct Routine {
impl Routine { impl Routine {
pub async fn validate_attr(routine_attr : &Vec<RoutineAttr>)
-> Result<String,String>
// [ ] => 03.27 - WIP
{
/*
GENERAL LOGIC :
[ ] 1. Define RoutineAttr in a broad level that are known to be implented or are work in progress
[ ] 2. Built in Logic will check these vectors, and return if Not Implemented
[ ] 3. If Implemented , then there are additional internal validation based on combination done later
*/
// [x] 1. Define RoutineAttr in a broad level that are known to be implented or are work in progress
// adjust the below for those that are work in progress or that are implemented
// - This will allow other functions to validate that it is implemented
// WORK IN PROGRESS VECTOR - Vec<$RoutineAttr>
let wip_attr:Vec<&RoutineAttr> = vec![
&RoutineAttr::RunOnce
];
let implemented_attr:Vec<&RoutineAttr> = vec![
];
// [x] 2. Built in Logic will check these vectors, and return if Not Implemented
let mut unimplemented = routine_attr.iter().filter(|x| !wip_attr.contains(x) && !implemented_attr.contains(x));
if unimplemented.next().is_some() {
botlog::trace(
"[ERROR][Routine Feature NOT IMPLEMENTED]",
Some("Routine > Validate_attr()".to_string()),
None,
);
Log::flush();
return Err("NOT IMPLEMENTED".to_string());
}
// [ ] 3. If Implemented , then there are additional internal validation based on combination done later
if routine_attr.contains(&RoutineAttr::RunOnce) {
return Ok("Valid & Implemented Setup".to_string())
}
botlog::trace(
"[ERROR][Routine Feature NOT IMPLEMENTED]",
Some("Routine > Validate_attr()".to_string()),
None,
);
Log::flush();
return Err("NOT IMPLEMENTED".to_string())
}
pub async fn validate_self_attr(self)
-> Result<String,String>
// [x] => 03.27 - COMPLETED
{
Routine::validate_attr(&self.routine_attr).await
}
// Constructor // Constructor
pub fn from( pub async fn from(
name : String , name : String ,
module : BotModule , module : BotModule ,
channel : Channel, channel : Channel,
@ -642,35 +725,34 @@ impl Routine {
) -> Result< ) -> Result<
Arc<RwLock<Routine>>, Arc<RwLock<Routine>>,
String String
> { >
// [x] => 03.27 - COMPLETED
{
// [ ] Validation is made against parent_params Routine::validate_attr(&routine_attr).await?;
// to ensure those params don't conflict
// conlicts would throw an error
if routine_attr.contains(&RoutineAttr::RunOnce) { return Ok(Arc::new(RwLock::new(Routine {
return Ok(Arc::new(RwLock::new(Routine { name ,
name , module ,
module , channel ,
channel , exec_body ,
exec_body , parent_params ,
parent_params , join_handle : None ,
join_handle : None , start_time : None ,
start_time : None , complete_iterations : 0 ,
complete_iterations : 0 , remaining_iterations : None ,
remaining_iterations : None , routine_attr : routine_attr
routine_attr : routine_attr }))) ;
}))) ;
}
Err("NOT IMPLEMENTED".to_string())
} }
pub fn change_channel( pub fn change_channel(
&self, &self,
_channel : Channel _channel : Channel
) -> Result<String,String> { ) -> Result<String,String>
// [ ] => 03.27 - WIP - NOT IMPLEMENTED
{
// [ ] Think Ideally it should try to // [ ] Think Ideally it should try to
// change the target channel of the // change the target channel of the
// internal process too if possible? // internal process too if possible?
@ -682,6 +764,7 @@ impl Routine {
trg_routine_ar : Arc<RwLock<Routine>> trg_routine_ar : Arc<RwLock<Routine>>
// ) -> Result<String,String> // ) -> Result<String,String>
) -> Result<Arc<RwLock<Routine>>,String> ) -> Result<Arc<RwLock<Routine>>,String>
// [ ] => 03.27 - WIP
{ {
// [ ] Asyncio Spawn likely around here // [ ] Asyncio Spawn likely around here
@ -703,28 +786,30 @@ impl Routine {
// Use the following to stop the function from going any further if not implemented // Use the following to stop the function from going any further if not implemented
if !trg_routine_ar.read().await.routine_attr.contains(&RoutineAttr::RunOnce) {
Routine::validate_attr(&trg_routine_ar.read().await.routine_attr).await?;
// if !trg_routine_ar.read().await.routine_attr.contains(&RoutineAttr::RunOnce) {
botlog::trace( // botlog::trace(
format!( // format!(
"[ERROR][Routine Feature NOT IMPLEMENTED] {} in {}", // "[ERROR][Routine Feature NOT IMPLEMENTED] {} in {}",
trg_routine_ar.read().await.name, // trg_routine_ar.read().await.name,
trg_routine_ar.read().await.channel.0 // trg_routine_ar.read().await.channel.0
) // )
.as_str(), // .as_str(),
Some(format!( // Some(format!(
"Routine > start() > (In Tokio Spawn) > {:?}", // "Routine > start() > (In Tokio Spawn) > {:?}",
trg_routine_ar.read().await.module // trg_routine_ar.read().await.module
)), // )),
Some(&trg_routine_ar.read().await.parent_params.msg), // Some(&trg_routine_ar.read().await.parent_params.msg),
); // );
Log::flush(); // Log::flush();
return Err("NOT IMPLEMENTED".to_string()) // return Err("NOT IMPLEMENTED".to_string())
} // }
let trg_routine_arout = Arc::clone(&trg_routine_ar); let trg_routine_arout = Arc::clone(&trg_routine_ar);
@ -773,6 +858,7 @@ impl Routine {
} }
// End of Loop Validation // End of Loop Validation
// These generally may include routine_attr related checks
if trg_routine_ar.read().await.routine_attr.contains(&RoutineAttr::RunOnce) { if trg_routine_ar.read().await.routine_attr.contains(&RoutineAttr::RunOnce) {
if trg_routine_ar.read().await.complete_iterations > 0 { break; } if trg_routine_ar.read().await.complete_iterations > 0 { break; }
@ -825,6 +911,7 @@ impl Routine {
async fn loopbody(&self) async fn loopbody(&self)
// [x] => 03.27 - COMPLETED
{ {
botlog::trace( botlog::trace(
"loopbody() started", "loopbody() started",
@ -842,6 +929,7 @@ impl Routine {
} }
pub async fn stop(&self) -> Result<String,String> pub async fn stop(&self) -> Result<String,String>
// [ ] => 03.27 - WIP - NOT IMPLEMENTED
{ {
@ -871,6 +959,7 @@ impl Routine {
&self, &self,
_force : bool _force : bool
) -> Result<String,String> ) -> Result<String,String>
// [ ] => 03.27 - WIP - NOT IMPLEMENTED
{ {
// force flag aborts the routine immediately (like cancel()) // force flag aborts the routine immediately (like cancel())
@ -897,6 +986,7 @@ impl Routine {
} }
pub async fn cancel(&self) -> Result<String,String> pub async fn cancel(&self) -> Result<String,String>
// [ ] => 03.27 - WIP - NOT IMPLEMENTED
{ {
// [ ] Likely calls abort() // [ ] Likely calls abort()