5cae3ba93de1a2023cd4e6084ec900f53bda6405
The library is not intended to handle this many tasks created so fast, and as such it is not optimized for. Generally we only allow a single modifier to the process manager at once. However, even then it can start and run a lot of tasks at once. Note that these processes, are comparable to pods / wasm containers / etc. And as such it wouldn't be realistic to run so many in parallel. Signed-off-by: kjuulh <contact@kjuulh.io>
noprocess
A lightweight Rust library for managing long-running processes with graceful shutdown, restart capabilities, and error handling.
Designed to work with nocontrol for distributed orchestration of Rust workloads — think Kubernetes pods, but for native Rust code.
Usage
use noprocess::{Process, ProcessHandler, ProcessManager, ProcessResult};
use tokio_util::sync::CancellationToken;
struct MyPipeline;
impl ProcessHandler for MyPipeline {
fn call(&self, cancel: CancellationToken) -> impl Future<Output = ProcessResult> + Send {
async move {
loop {
tokio::select! {
_ = cancel.cancelled() => break,
_ = do_work() => {}
}
}
Ok(())
}
}
}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let manager = ProcessManager::new();
let id = manager.add_process(Process::new(MyPipeline)).await;
manager.start_process(&id).await?;
// Later: stop, restart, or kill
manager.stop_process(&id).await?;
Ok(())
}
Features
- Graceful shutdown — processes receive a cancellation token and can clean up
- Configurable timeouts — force-kill stubborn processes after a deadline
- Auto-restart — optionally restart processes that complete successfully
- Error callbacks — handle failures and panics with custom logic
- Process lifecycle — start, stop, restart, kill individual processes
Examples
cargo run --bin simple # Basic start/stop/restart
cargo run --bin pipeline # Data pipeline with backpressure
cargo run --bin worker # Worker pool pattern
License
MIT
Languages
Rust
100%
