#grpc #grpc-server #long-running #manager #async-trait #lifecycle #life-cycle

notmad

notmad is a life-cycle manager for long running rust operations

5 releases (3 breaking)

0.7.1 Nov 24, 2024
0.7.0 Nov 24, 2024
0.6.0 Nov 23, 2024
0.5.0 Nov 19, 2024
0.4.0 Nov 8, 2024

#606 in Asynchronous

Download history 76/week @ 2024-11-27 30/week @ 2024-12-04 12/week @ 2024-12-11 53/week @ 2025-01-08 24/week @ 2025-01-15 35/week @ 2025-01-22 40/week @ 2025-01-29 53/week @ 2025-02-05 49/week @ 2025-02-12 52/week @ 2025-02-19 55/week @ 2025-02-26 5/week @ 2025-03-05 13/week @ 2025-03-12

135 downloads per month
Used in nodata

MIT license

12KB
243 lines

MAD

Mad is a life-cycle manager for long running rust operations.

  • Webservers
  • Queue bindings
  • gRPC servers etc
  • Cron runners

It is supposed to be the main thing the application runs, and everything from it is spawned and managed by it.

struct WaitServer {}

#[async_trait]
impl Component for WaitServer {
    fn name(&self) -> Option<String> {
        Some("NeverEndingRun".into())
    }

    async fn run(&self, cancellation: CancellationToken) -> Result<(), mad::MadError> {
        let millis_wait = rand::thread_rng().gen_range(50..1000);

        // Simulates a server running for some time. Is normally supposed to be futures blocking indefinitely
        tokio::time::sleep(std::time::Duration::from_millis(millis_wait)).await;

        Ok(())
    }
}

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    Mad::builder()
        .add(WaitServer {})
        .add(WaitServer {})
        .add(WaitServer {})
        .run()
        .await?;

    Ok(())
}

Examples

Can be found (here)crates/mad/examples

  • basic
  • fn
  • signals
  • error_log

Dependencies

~4–11MB
~110K SLoC