MAD - Lifecycle Manager for Rust Applications
MAD is a robust lifecycle manager designed for long-running Rust operations. It provides a simple, composable way to manage multiple concurrent services within your application, handling graceful startup and shutdown automatically.
Overview
MAD helps you build applications composed of multiple long-running components that need to be orchestrated together. It handles:
- Concurrent execution of multiple components
- Graceful shutdown with cancellation tokens
- Error aggregation from multiple components
- Lifecycle management with setup, run, and close phases
Quick Start
use ;
use async_trait;
use CancellationToken;
async
Component Lifecycle
Components go through three phases:
- Setup: Optional initialization phase before components start running
- Run: Main execution phase where components perform their work
- Close: Optional cleanup phase after components stop
Error Handling
MAD provides comprehensive error handling through [MadError], which can:
- Wrap errors from individual components
- Aggregate multiple errors when several components fail
- Automatically convert from
anyhow::Error
Shutdown Behavior
MAD handles shutdown gracefully:
- Responds to SIGTERM and Ctrl+C signals
- Propagates cancellation tokens to all components
- Waits for components to finish cleanup
- Configurable cancellation timeout