Supervisor

Struct Supervisor 

Source
pub struct Supervisor { /* private fields */ }
Expand description

Supervisor that manages a set of processes

Implementations§

Source§

impl Supervisor

Source

pub fn new(config: SupervisorConfig) -> Self

Creates a new supervisor with the specified configuration

§Arguments
  • config - Supervisor configuration
§Example
use rust_supervisor::{Supervisor, SupervisorConfig};
let supervisor = Supervisor::new(SupervisorConfig::default());
Source

pub fn with_callback( config: SupervisorConfig, callback: Arc<dyn EventCallback>, ) -> Self

Creates a new supervisor with a custom event callback

Source

pub fn add_process<F>(&mut self, name: &str, child_type: ChildType, factory: F)
where F: Fn() -> JoinHandle<()> + Send + 'static,

Adds a process to monitor

§Arguments
  • name - Unique process name
  • child_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...
    })
});
Source

pub fn add_process_with_shutdown<F>( &mut self, name: &str, child_type: ChildType, factory: F, shutdown_strategy: ShutdownStrategy, )
where F: Fn() -> JoinHandle<()> + Send + 'static,

Adds a process with custom shutdown strategy

Source

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 another
  • depends_on - Name of the process that the first one depends on
Source

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 for convenience chaining.

Source

pub fn stop_process(&self, name: &str) -> bool

Manually stops a process with graceful shutdown

§Arguments
  • name - Name of the process to stop
§Returns

true if the process was found and stopped, false otherwise

Source

pub fn shutdown(&self)

Stops all processes gracefully

Source

pub fn get_process_state(&self, name: &str) -> Option<ProcessState>

Gets the current state of a process

§Arguments
  • name - Process name
§Returns

The process state, or None if the process doesn’t exist

Source

pub fn get_restart_count(&self, name: &str) -> Option<usize>

Gets the restart count for a process

Source

pub fn get_all_states(&self) -> HashMap<String, (ProcessState, usize)>

Gets all process states

Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.