1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
/// Manage multiple running services. A ProcessManager collects impl of `Runnable`
/// and takes over the runtime management like starting, stopping (graceful or in
/// failure) of services.
///
/// ```rust
/// use processmanager::*;
///
/// #[tokio::main]
/// async fn main() {
///
/// #[derive(Default)]
/// struct ExampleController {
/// runtime_guard: RuntimeGuard,
/// }
///
/// #[async_trait::async_trait]
/// impl Runnable for ExampleController {
/// async fn process_start(&self) -> Result<(), RuntimeError> {
/// // This can be any type of future like an async streams
/// let mut interval = tokio::time::interval(tokio::time::Duration::from_secs(1));
///
/// loop {
/// match self.runtime_guard.tick(interval.tick()).await {
/// ProcessOperation::Next(_) => println!("work"),
/// ProcessOperation::Control(RuntimeControlMessage::Shutdown) => {
/// println!("shutdown");
/// break
/// },
/// ProcessOperation::Control(RuntimeControlMessage::Reload) => println!("trigger relead"),
/// }
/// }
///
/// Ok(())
/// }
///
/// fn process_handle(&self) -> Box<dyn ProcessControlHandler> {
/// Box::new(self.runtime_guard.handle())
/// }
/// }
///
/// let mut manager = ProcessManager::new();
/// manager.insert(SignalReceiver::default());
/// manager.insert(ExampleController::default());
///
/// let handle = manager.process_handle();
///
/// // start all processes
/// let _ = tokio::spawn(async move {
/// manager.process_start().await.expect("service start failed");
/// });
///
/// // Shutdown waits for all services to shutdown gracefully.
/// handle.shutdown().await;
/// }
/// ```
///
mod error;
mod process_manager;
mod process_signal_receiver;
mod runtime_process;
pub use error::*;
pub use process_manager::*;
pub use process_signal_receiver::*;
pub use runtime_process::*;