ProcessManager

Struct ProcessManager 

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

Manages external child processes with graceful shutdown and dependency ordering

ProcessManager tracks and manages child processes spawned as external binaries. It provides:

  • Process tracking with PIDs
  • Dependency-based shutdown ordering
  • Graceful shutdown with configurable timeout
  • Force kill fallback
  • Integration with runtime’s ShutdownHandle

Implementations§

Source§

impl ProcessManager

Source

pub fn new() -> Self

Create a new process manager

Source

pub fn with_shutdown_handle(shutdown_handle: ShutdownHandle) -> Self

Create a new process manager with shutdown handle

Source

pub fn set_shutdown_timeout(&mut self, timeout: Duration)

Set the default shutdown timeout

Source

pub fn track(&mut self, name: String, child: Child)

Add a process to track

§Arguments
  • name - Process name/identifier
  • child - Child process handle
Source

pub fn remove(&mut self, name: &str) -> Option<Child>

Remove and return a process by name

Source

pub fn add_dependency(&mut self, node: String, dependency: String)

Add a dependency relationship

Specifies that node depends on dependency and should be stopped before it.

§Arguments
  • node - The node that depends on another
  • dependency - The node that is depended upon
Source

pub fn list(&self) -> Vec<String>

Get list of all tracked process names

Source

pub fn len(&self) -> usize

Get the number of tracked processes

Source

pub fn is_empty(&self) -> bool

Check if any processes are being tracked

Source

pub fn status_all(&mut self) -> HashMap<String, ProcessStatus>

Get status of all processes

Source

pub fn processes(&mut self) -> Vec<ProcessInfo>

Get information about all tracked processes

Source

pub fn shutdown_order(&self) -> Vec<String>

Calculate shutdown order based on dependency graph

Returns nodes in the order they should be stopped (dependents before dependencies).

Source

pub fn stop_graceful(&mut self, name: &str, timeout: Duration) -> Result<()>

Stop a specific process gracefully with timeout

§Arguments
  • name - Name of the process to stop
  • timeout - How long to wait for graceful shutdown before force killing
§Returns

Ok(()) if stopped successfully (graceful or force), Err if not found or error

Source

pub fn force_kill(&mut self, name: &str) -> Result<()>

Force kill a process immediately

Source

pub fn shutdown_all(&mut self)

Stop all processes in dependency order with graceful shutdown

Source

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

Check if a specific process is running

Trait Implementations§

Source§

impl Default for ProcessManager

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Drop for ProcessManager

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more