Skip to main content

ProcessService

Struct ProcessService 

Source
pub struct ProcessService { /* private fields */ }

Implementations§

Source§

impl ProcessService

Source

pub fn build_node(&self, node_name: &str, release: bool) -> Result<()>

Build a node binary if needed

Helper method to build a specific node package

§Arguments
  • node_name - Name of the node to build
  • release - Whether to build in release mode
Source

pub fn build_all(&self, release: bool) -> Result<()>

Build all nodes in the workspace

§Arguments
  • release - Whether to build in release mode
Source§

impl ProcessService

Source

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

Get status of all processes

Returns a HashMap mapping process names to status strings

Source

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

Stop a specific process by name

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

Returns an error if the process is not found

Note: This uses a default 10-second timeout for graceful shutdown. Use stop_with_timeout() for custom timeout.

Source

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

Stop a process with timeout for graceful shutdown

Tries graceful shutdown (SIGTERM on Unix), then force kills after timeout

§Arguments
  • name - Name of the process to stop
  • timeout - How long to wait for graceful shutdown
§Errors

Returns an error if process not found or cannot be stopped

Source

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

  • name - Name of the process to kill
Source

pub fn cleanup(&mut self)

Stop all processes gracefully in dependency order

This delegates to the runtime’s ProcessManager which handles:

  • Dependency-based shutdown ordering
  • Graceful shutdown with timeout
  • Force kill fallback
Source

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

  • name - Name of the process to check
Source

pub fn restart( &mut self, name: &str, binary_path: &str, args: &[&str], ) -> Result<u32>

Restart a specific process

Stops the process if running and starts it again

§Arguments
  • name - Name of the process
  • binary_path - Path to the binary
  • args - Command-line arguments
Source

pub fn restart_all( &mut self, nodes: Vec<(&str, &str, Vec<&str>)>, ) -> Result<HashMap<String, u32>>

Restart all processes

§Arguments
  • nodes - Vec of (name, binary_path, args) tuples
Source§

impl ProcessService

Source

pub fn find_global_binary(node_name: &str) -> Option<PathBuf>

Find globally installed binary for a node

Searches in:

  1. ~/.cargo/bin/{node_name}
  2. ~/.mecha10/bin/{node_name}
§Arguments
  • node_name - Name of the node (e.g., “camera”)
§Returns

Path to the binary if found, None otherwise

Source

pub fn resolve_node_runner_path() -> String

Resolve path to mecha10-node-runner binary

Resolution strategy:

  1. Global installation: ~/.cargo/bin/mecha10-node-runner
  2. Fallback: “mecha10-node-runner” (rely on PATH)
§Returns

Path to the mecha10-node-runner binary

Source

pub fn is_node_runner_available() -> bool

Check if mecha10-node-runner is available

Source§

impl ProcessService

Source

pub fn spawn_node( &mut self, name: &str, binary_path: &str, args: &[&str], ) -> Result<u32>

Spawn a node process

§Arguments
  • name - Name to identify the process
  • binary_path - Path to the binary to execute
  • args - Command-line arguments
§Errors

Returns an error if the process cannot be spawned

Source

pub fn spawn_with_output( &mut self, name: &str, binary_path: &str, args: &[&str], ) -> Result<u32>

Spawn a process with output capture

§Arguments
  • name - Name to identify the process
  • binary_path - Path to the binary to execute
  • args - Command-line arguments
§Errors

Returns an error if the process cannot be spawned

Source

pub fn spawn_with_env( &mut self, name: &str, binary_path: &str, args: &[&str], env: HashMap<String, String>, ) -> Result<u32>

Spawn a process with custom environment variables

§Arguments
  • name - Name to identify the process
  • binary_path - Path to the binary to execute
  • args - Command-line arguments
  • env - Environment variables to set
Source

pub fn spawn_in_dir( &mut self, name: &str, binary_path: &str, args: &[&str], working_dir: impl AsRef<Path>, ) -> Result<u32>

Spawn a process in a specific working directory

§Arguments
  • name - Name to identify the process
  • binary_path - Path to the binary to execute
  • args - Command-line arguments
  • working_dir - Working directory for the process
Source

pub fn spawn_nodes( &mut self, nodes: Vec<(&str, &str, Vec<&str>)>, ) -> Result<HashMap<String, u32>>

Spawn multiple node processes from a list

§Arguments
  • nodes - Vec of (name, binary_path, args) tuples
§Returns

HashMap of node names to PIDs

Source§

impl ProcessService

Source

pub fn spawn_node_runner( &mut self, node_identifier: &str, project_name: &str, project_env: Option<HashMap<String, String>>, ) -> Result<u32>

Spawn a node using mecha10-node-runner

This is the simplified spawning method for Phase 2+ of Node Lifecycle Architecture. It delegates all complexity (binary resolution, model pulling, env setup) to node-runner.

§Returns

Process ID of the spawned node-runner instance

§Errors

Returns an error if the node-runner cannot be spawned

§Configuration

The node-runner reads configuration from the node’s config file (e.g., configs/nodes/{node_name}.json) and supports the following runtime settings:

{
  "runtime": {
    "restart_policy": "on-failure",  // never, on-failure, always
    "max_retries": 3,
    "backoff_secs": 1
  },
  "depends_on": ["camera", "lidar"],
  "startup_timeout_secs": 30
}

To enable dependency checking, use: mecha10-node-runner --wait-for-deps <node-name>

§Arguments
  • node_identifier - Full node identifier (e.g., @mecha10/simulator, my-node)
  • project_name - Name of the current project, forwarded to node-runner as the required --project flag, used to find the monorepo project binary at target/{release,debug}/{project_name}.
Source

pub fn spawn_node_direct( &mut self, node_identifier: &str, _project_name: &str, project_env: Option<HashMap<String, String>>, ) -> Result<u32>

Spawn a node directly (standalone mode)

This is used when mecha10-node-runner is not available (standalone projects installed from crates.io). Handles both framework nodes (via BinaryManager) and local project nodes (built and run directly).

Resolution strategy for framework nodes:

  1. Check ~/.mecha10/bin/ for a pre-downloaded binary
  2. If not found, download it via mecha10-api

There is no further fallback: an unsupported platform or a failed download is a hard error (see BinaryManager::resolve_with_version).

§Arguments
  • node_name - Name of the node to run
  • project_name - Name of the project (used to find the binary)
  • project_env - Optional additional environment variables from project config
§Returns

Process ID of the spawned node process

Source§

impl ProcessService

Source

pub fn new() -> Self

Create a new process service

Source

pub fn track_dependency(&mut self, node: &str, dependencies: Vec<String>)

Track dependency relationship for a node

§Arguments
  • node - Name of the node
  • dependencies - List of nodes this node depends on
Source

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

Get shutdown order (reverse dependency order)

Returns nodes in order they should be stopped:

  • Nodes with dependents first (high-level nodes)
  • Then their dependencies (low-level nodes)

This ensures we don’t stop a node while other nodes depend on it.

Delegates to the runtime’s ProcessManager.

Source

pub fn count(&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 manager(&mut self) -> &mut ProcessManager

Get access to the underlying ProcessManager

Useful for advanced operations or when migrating existing code. Provides direct access to the runtime’s ProcessManager.

Trait Implementations§

Source§

impl Default for ProcessService

Source§

fn default() -> Self

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

impl Drop for ProcessService

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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