ProcessManager

Struct ProcessManager 

Source
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

Source

pub fn new() -> LuhTwin<Self>

Creates a new ProcessManager and ensures the temporary directory for worker storage exists.

The directory is:

  • $LUHPROC_TMP_DIR if set
  • otherwise /tmp/luhproc (or debug temp dir in dev builds)
Source

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.

Source

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().

Source

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 PID
  • out.log — stdout of worker
  • err.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
Source

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.

Source

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

Source§

fn clone(&self) -> ProcessManager

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ProcessManager

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.