pub struct Supervisor { /* private fields */ }Expand description
Supervisor that manages a set of processes
Implementations§
Source§impl Supervisor
impl Supervisor
Sourcepub fn new(config: SupervisorConfig) -> Self
pub fn new(config: SupervisorConfig) -> Self
Sourcepub fn with_callback(
config: SupervisorConfig,
callback: Arc<dyn EventCallback>,
) -> Self
pub fn with_callback( config: SupervisorConfig, callback: Arc<dyn EventCallback>, ) -> Self
Creates a new supervisor with a custom event callback
Sourcepub fn add_process<F>(&mut self, name: &str, child_type: ChildType, factory: F)
pub fn add_process<F>(&mut self, name: &str, child_type: ChildType, factory: F)
Adds a process to monitor
§Arguments
name- Unique process namechild_type- Type of child (Permanent, Temporary, Transient)factory- Function that creates and starts the process
§Example
ⓘ
use rust_supervisor::{Supervisor, SupervisorConfig, ChildType};
use std::thread;
let mut supervisor = Supervisor::new(SupervisorConfig::default());
supervisor.add_process("worker", ChildType::Permanent, || {
thread::spawn(|| {
// Worker code...
})
});Sourcepub fn add_process_with_shutdown<F>(
&mut self,
name: &str,
child_type: ChildType,
factory: F,
shutdown_strategy: ShutdownStrategy,
)
pub fn add_process_with_shutdown<F>( &mut self, name: &str, child_type: ChildType, factory: F, shutdown_strategy: ShutdownStrategy, )
Adds a process with custom shutdown strategy
Sourcepub fn add_dependency(&self, process: &str, depends_on: &str)
pub fn add_dependency(&self, process: &str, depends_on: &str)
Declares a dependency between two processes
§Arguments
process- Name of the process that depends on anotherdepends_on- Name of the process that the first one depends on
Sourcepub fn start_monitoring(self) -> Arc<Self>where
Self: Sized,
pub fn start_monitoring(self) -> Arc<Self>where
Self: Sized,
Starts monitoring processes
This method launches a monitoring thread that periodically checks the state of processes and restarts them according to the configured strategy.
Returns Arc
Sourcepub fn stop_process(&self, name: &str) -> bool
pub fn stop_process(&self, name: &str) -> bool
Sourcepub fn get_process_state(&self, name: &str) -> Option<ProcessState>
pub fn get_process_state(&self, name: &str) -> Option<ProcessState>
Sourcepub fn get_restart_count(&self, name: &str) -> Option<usize>
pub fn get_restart_count(&self, name: &str) -> Option<usize>
Gets the restart count for a process
Sourcepub fn get_all_states(&self) -> HashMap<String, (ProcessState, usize)>
pub fn get_all_states(&self) -> HashMap<String, (ProcessState, usize)>
Gets all process states
Sourcepub fn get_shutdown_signal(&self, name: &str) -> Option<Arc<AtomicBool>>
pub fn get_shutdown_signal(&self, name: &str) -> Option<Arc<AtomicBool>>
Get the shutdown signal for a process (for graceful shutdown detection)
Auto Trait Implementations§
impl Freeze for Supervisor
impl !RefUnwindSafe for Supervisor
impl Send for Supervisor
impl Sync for Supervisor
impl Unpin for Supervisor
impl !UnwindSafe for Supervisor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more