WIP: Routine Unresponsive due to Deadlock #51

Draft
modulatingforce wants to merge 10 commits from issue-routine-lock into routines-functionality
5 changed files with 38 additions and 5 deletions
Showing only changes of commit fcf4f3f7cf - Show all commits

View file

@ -12,7 +12,7 @@ pub type BotAR = Arc<RwLock<BotInstance>>;
pub type ActAR = Arc<RwLock<BotAction>>;
pub type RoutineAR = Arc<RwLock<Routine>>;
#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct ExecBodyParams {
pub bot : BotAR,
pub msg : PrivmsgMessage,

View file

@ -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<RwLock<IdentityManager>>,
pub chat: Chat,
@ -70,6 +70,7 @@ impl<T: Clone> ArcBox<T> {
}
}
#[derive(Debug)]
pub struct BotInstance {
pub prefix: char,
pub bot_channel: Channel,

View file

@ -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)
}
}
Review

Holy I love this idea! 🤤 with the others too!

Holy I love this idea! 🤤 with the others too!
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<ActAR> ,
}
// 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<StatusType>);
type ModuleActions = Vec<Arc<RwLock<BotAction>>>;
#[derive(Debug)]
pub struct ModulesManager {
statusdb: Arc<RwLock<HashMap<BotModule, StatusdbEntry>>>,
pub botactions: Arc<RwLock<HashMap<BotModule, ModuleActions>>>,

View file

@ -27,7 +27,7 @@ use super::identity;
use async_recursion::async_recursion;
#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct Chat {
pub ratelimiters: Arc<Mutex<HashMap<Channel, RateLimiter>>>, // used to limit messages sent per channel
pub client: TwitchIRCClient<TCPTransport<TLS>, StaticLoginCredentials>,

View file

@ -698,7 +698,7 @@ pub enum Permissible {
type UserRolesDB = HashMap<String, Arc<RwLock<Vec<UserRole>>>>;
#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct IdentityManager {
special_roles_users: Arc<RwLock<UserRolesDB>>,
}