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
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 is_framework_dev_mode() -> bool
pub fn is_framework_dev_mode() -> bool
Check if we’re in framework development mode
Framework dev mode is detected by:
- MECHA10_FRAMEWORK_PATH environment variable
- Existence of .cargo/config.toml with patches
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 framework dev mode: use local build (target/debug or target/release)
- 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:
- Framework dev mode: $MECHA10_FRAMEWORK_PATH/target/release/mecha10-node-runner
- Global installation: ~/.cargo/bin/mecha10-node-runner
- Fallback: “mecha10-node-runner” (rely on PATH)
§Returns
Path to the mecha10-node-runner binary
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
Sourcepub fn spawn_nodes(
&mut self,
nodes: Vec<(&str, &str, Vec<&str>)>,
) -> Result<HashMap<String, u32>>
pub fn spawn_nodes( &mut self, nodes: Vec<(&str, &str, Vec<&str>)>, ) -> Result<HashMap<String, u32>>
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
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.
Sourcepub fn build_node(&self, node_name: &str, release: bool) -> Result<()>
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 buildrelease- Whether to build in release mode
Sourcepub fn build_from_framework(
&self,
package_name: &str,
release: bool,
) -> Result<()>
pub fn build_from_framework( &self, package_name: &str, release: bool, ) -> Result<()>
Build a binary from the framework monorepo
This builds a binary from the framework path (MECHA10_FRAMEWORK_PATH).
Used for binaries like mecha10-node-runner that exist in the monorepo
but need to be built when running from a generated project.
§Arguments
package_name- Name of the package to build (e.g., “mecha10-node-runner”)release- Whether to build in release mode
§Returns
Ok(()) on success, or error if build fails or framework path not set
Sourcepub fn build_project_packages(&self, release: bool) -> Result<()>
pub fn build_project_packages(&self, release: bool) -> Result<()>
Build only packages needed by the current project (smart selective build)
For generated projects, this just builds the project binary. Cargo automatically builds only the dependencies actually used. With .cargo/config.toml patches, this rebuilds framework packages from source.
§Arguments
release- Whether to build in release mode
§Returns
Ok(()) on success, or error if build fails
Sourcepub fn restart(
&mut self,
name: &str,
binary_path: &str,
args: &[&str],
) -> Result<u32>
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 processbinary_path- Path to the binaryargs- Command-line arguments
Sourcepub fn restart_all(
&mut self,
nodes: Vec<(&str, &str, Vec<&str>)>,
) -> Result<HashMap<String, u32>>
pub fn restart_all( &mut self, nodes: Vec<(&str, &str, Vec<&str>)>, ) -> Result<HashMap<String, u32>>
Sourcepub fn spawn_node_runner(
&mut self,
node_name: &str,
project_env: Option<HashMap<String, String>>,
) -> Result<u32>
pub fn spawn_node_runner( &mut self, node_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.
§Arguments
node_name- Name of the node to run
§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>
Sourcepub fn spawn_node_direct(
&mut self,
node_name: &str,
project_name: &str,
project_env: Option<HashMap<String, String>>,
) -> Result<u32>
pub fn spawn_node_direct( &mut self, node_name: &str, project_name: &str, project_env: Option<HashMap<String, String>>, ) -> Result<u32>
Spawn a node directly via the project binary (standalone mode)
This is used when mecha10-node-runner is not available (standalone projects
installed from crates.io). It directly calls the project binary with node <name>.
§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
Sourcepub fn is_node_runner_available() -> bool
pub fn is_node_runner_available() -> bool
Check if mecha10-node-runner is available
Trait Implementations§
Source§impl Default for ProcessService
impl Default for ProcessService
Auto Trait Implementations§
impl Freeze for ProcessService
impl !RefUnwindSafe for ProcessService
impl Send for ProcessService
impl Sync for ProcessService
impl Unpin for ProcessService
impl !UnwindSafe 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