pub struct ProcessService { /* private fields */ }Expand description
Process service for managing child processes
This is a thin wrapper around the runtime’s ProcessManager, adding CLI-specific conveniences and delegating core functionality to the runtime layer.
§Examples
use mecha10_cli::services::ProcessService;
let mut service = ProcessService::new();
// Spawn a node process
service.spawn_node("camera_driver", "target/debug/camera_driver", &[])?;
// Check status
let status = service.get_status();
println!("Running processes: {:?}", status);
// Stop a specific process
service.stop("camera_driver")?;
// Cleanup all processes
service.cleanup();Implementations§
Source§impl ProcessService
impl ProcessService
Source§impl ProcessService
impl ProcessService
Sourcepub fn get_status(&mut self) -> HashMap<String, String>
pub fn get_status(&mut self) -> HashMap<String, String>
Get status of all processes
Returns a HashMap mapping process names to status strings
Sourcepub fn force_kill(&mut self, name: &str) -> Result<()>
pub fn force_kill(&mut self, name: &str) -> Result<()>
Sourcepub fn cleanup(&mut self)
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
Sourcepub fn is_running(&mut self, name: &str) -> bool
pub fn is_running(&mut self, name: &str) -> bool
Source§impl ProcessService
impl ProcessService
Sourcepub fn find_global_binary(node_name: &str) -> Option<PathBuf>
pub fn find_global_binary(node_name: &str) -> Option<PathBuf>
Sourcepub fn resolve_node_binary(
node_name: &str,
is_monorepo_node: bool,
project_name: &str,
) -> String
pub fn resolve_node_binary( node_name: &str, is_monorepo_node: bool, project_name: &str, ) -> String
Resolve binary path for a node with smart resolution
Resolution strategy:
- If global binary exists: use global binary
- Fallback: use local build path
§Arguments
node_name- Name of the nodeis_monorepo_node- Whether this is a framework nodeproject_name- Name of the project
§Returns
Path to the binary to execute
Sourcepub fn resolve_node_runner_path() -> String
pub fn resolve_node_runner_path() -> String
Resolve path to mecha10-node-runner binary
Resolution strategy:
- Global installation: ~/.cargo/bin/mecha10-node-runner
- Fallback: “mecha10-node-runner” (rely on PATH)
§Returns
Path to the mecha10-node-runner binary
Sourcepub fn is_node_runner_available() -> bool
pub fn is_node_runner_available() -> bool
Check if mecha10-node-runner is available
Source§impl ProcessService
impl ProcessService
Sourcepub fn spawn_with_output(
&mut self,
name: &str,
binary_path: &str,
args: &[&str],
) -> Result<u32>
pub fn spawn_with_output( &mut self, name: &str, binary_path: &str, args: &[&str], ) -> Result<u32>
Sourcepub fn spawn_with_env(
&mut self,
name: &str,
binary_path: &str,
args: &[&str],
env: HashMap<String, String>,
) -> Result<u32>
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 processbinary_path- Path to the binary to executeargs- Command-line argumentsenv- Environment variables to set
Sourcepub fn spawn_in_dir(
&mut self,
name: &str,
binary_path: &str,
args: &[&str],
working_dir: impl AsRef<Path>,
) -> Result<u32>
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 processbinary_path- Path to the binary to executeargs- Command-line argumentsworking_dir- Working directory for the process
Source§impl ProcessService
impl ProcessService
Sourcepub fn spawn_node_runner(
&mut self,
node_identifier: &str,
project_name: &str,
project_env: Option<HashMap<String, String>>,
) -> Result<u32>
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--project. Without this, node-runner falls back to guessing the project name from its own current working directory’s basename (see itsresolve_node_execution) to find the monorepo project binary attarget/{release,debug}/{project_name}- a guess that silently breaks whenever the working directory’s name doesn’t match the actual Cargo package/binary name (e.g. a checkout cloned into a differently-named directory). That misresolution is what made bundled framework nodes (@mecha10/*) appear to fail under node-runner: with no monorepo binary found under the guessed name, node-runner falls through to its bundled-node fallback, which shells out to the globally installedmecha10CLI asmecha10 node <name>- a subcommand themecha10CLI binary (packages/cli) doesn’t define, so that fallback always fails too. Passing the real project name explicitly removes the guess entirely.
Sourcepub fn spawn_node_direct(
&mut self,
node_identifier: &str,
_project_name: &str,
project_env: Option<HashMap<String, String>>,
) -> Result<u32>
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:
- Check ~/.mecha10/bin/ for pre-downloaded binary
- If not found, attempt to download from GitHub releases
- If download fails, fall back to cargo install
§Arguments
node_name- Name of the node to runproject_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
impl ProcessService
Sourcepub fn track_dependency(&mut self, node: &str, dependencies: Vec<String>)
pub fn track_dependency(&mut self, node: &str, dependencies: Vec<String>)
Track dependency relationship for a node
§Arguments
node- Name of the nodedependencies- List of nodes this node depends on
Sourcepub fn get_shutdown_order(&self) -> Vec<String>
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.
Sourcepub fn manager(&mut self) -> &mut ProcessManager
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
impl Default for ProcessService
Source§impl Drop for ProcessService
impl Drop for ProcessService
Auto Trait Implementations§
impl !RefUnwindSafe for ProcessService
impl !UnwindSafe for ProcessService
impl Freeze for ProcessService
impl Send for ProcessService
impl Sync for ProcessService
impl Unpin for ProcessService
impl UnsafeUnpin for ProcessService
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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