pub struct ProcessManager {
pub tasks: Vec<ChildTask>,
}Expand description
Central controller responsible for registering tasks, launching background workers, inspecting them, and stopping them.
Usually created through the process_manager! macro.
Fields§
§tasks: Vec<ChildTask>Implementations§
Source§impl ProcessManager
impl ProcessManager
Sourcepub fn new() -> LuhTwin<Self>
pub fn new() -> LuhTwin<Self>
Creates a new ProcessManager and ensures the temporary directory
for worker storage exists.
The directory is:
$LUHPROC_TMP_DIRif set- otherwise
/tmp/luhproc(or debug temp dir in dev builds)
Sourcepub fn register_task(&mut self, env_var: &'static str, work: ChildWorkFn)
pub fn register_task(&mut self, env_var: &'static str, work: ChildWorkFn)
Registers a task using its environment trigger and work function.
Most applications use the process_manager! macro instead.
Sourcepub fn check(&self) -> LuhTwin<()>
pub fn check(&self) -> LuhTwin<()>
Detects whether the current process was started as a background worker.
If the triggering environment variable is set, this method:
- runs the task function immediately
- logs its start time
- and terminates the process afterwards
If no task matches, this is a no-op and returns normally.
Call this at the beginning of main().
Sourcepub fn start(
&self,
task_name: &str,
id: impl Into<String>,
extra_env: Option<HashMap<String, String>>,
) -> LuhTwin<()>
pub fn start( &self, task_name: &str, id: impl Into<String>, extra_env: Option<HashMap<String, String>>, ) -> LuhTwin<()>
Starts a background worker process for the given task.
This works by re-invoking the current executable with the task’s
environment variable set, allowing the process to enter worker mode
during check().
Creates the directory:
<tmp>/luhproc/<task-name-hash>/Inside:
pid— worker PIDout.log— stdout of workererr.log— stderr of worker
§Errors
- If the task is unknown
- If the PID file already exists (worker already running)
- If the process fails to spawn
Sourcepub fn info(&self, task_name: &str, id: impl Into<String>) -> LuhTwin<String>
pub fn info(&self, task_name: &str, id: impl Into<String>) -> LuhTwin<String>
Returns a human-readable summary of the worker instance:
task: MY_TASK (id: session42)
pid: 39241
directory: /tmp/luhproc/my-task-a8fd93c2e1a3
log file: ...
error file: ...If the worker is not running or has an invalid PID file, a descriptive message is returned.
Sourcepub fn stop(
&self,
task_name: &str,
id: Option<impl Into<String> + Clone>,
) -> LuhTwin<()>
pub fn stop( &self, task_name: &str, id: Option<impl Into<String> + Clone>, ) -> LuhTwin<()>
Stops a running worker by sending it SIGTERM.
If id is given:
- stops only that specific instance
If id is None:
- stops all workers whose directory names match the task
After a worker is stopped, its directory is removed.
§Errors
- If no matching workers are found
- If killing any worker fails
Trait Implementations§
Source§impl Clone for ProcessManager
impl Clone for ProcessManager
Source§fn clone(&self) -> ProcessManager
fn clone(&self) -> ProcessManager
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more