62
README.md
Normal file
62
README.md
Normal file
@@ -0,0 +1,62 @@
|
||||
# noprocess
|
||||
|
||||
A lightweight Rust library for managing long-running processes with graceful shutdown, restart capabilities, and error handling.
|
||||
|
||||

|
||||
|
||||
Designed to work with [nocontrol](https://git.kjuulh.io/kjuulh/nocontrol) for distributed orchestration of Rust workloads — think Kubernetes pods, but for native Rust code.
|
||||
|
||||
## Usage
|
||||
|
||||
```rust
|
||||
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
|
||||
|
||||
```sh
|
||||
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
|
||||
Reference in New Issue
Block a user