MAD - Lifecycle Manager for Rust Applications
Overview
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.
Perfect for:
- 🌐 Web servers
- 📨 Queue consumers and message processors
- 🔌 gRPC servers
- ⏰ Cron job runners
- 🔄 Background workers
- 📡 Any long-running async operations
Features
- Component-based architecture - Build your application from composable, reusable components
- Graceful shutdown - Automatic handling of shutdown signals with proper cleanup
- Concurrent execution - Run multiple components in parallel with tokio
- Error handling - Built-in error propagation and logging
- Cancellation tokens - Coordinate shutdown across all components
- Minimal boilerplate - Focus on your business logic, not lifecycle management
Installation
Add MAD to your Cargo.toml:
[]
= "0.7.5"
= { = "1", = ["full"] }
= "0.1"
Quick Start
Here's a simple example of a component that simulates a long-running server:
use ;
use async_trait;
use CancellationToken;
// Define your component
async
Advanced Usage
Custom Components
Components can be anything that implements the Component trait:
use ;
use async_trait;
Error Handling
MAD provides comprehensive error handling through the MadError type with automatic conversion from anyhow::Error:
async
Examples
Check out the examples directory for more detailed examples:
- basic - Simple component lifecycle
- fn - Using functions as components
- signals - Handling system signals
- error_log - Error handling and logging
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Author
Created and maintained by kjuulh
Repository
Find the source code at https://github.com/kjuulh/mad