aum_core/
monitor.rs

1use thiserror::Error;
2
3#[async_trait::async_trait]
4pub trait Monitor {
5    /// Type that represents wallet manager.
6    type WalletManager: crate::wallet::WalletManager + Send;
7
8    /// Start the monitor with the given scale.
9    async fn start(&self, scale: &mut Self::WalletManager) -> Result<(), MonitorError>;
10
11    /// Stop the monitor.
12    fn stop(&self) -> Result<(), MonitorError>;
13
14    /// Check if the monitor is currently running.
15    fn is_running(&self) -> bool;
16
17    /// Restart the monitor by stopping and starting it again.
18    async fn restart(&self, scale: &mut Self::WalletManager) -> Result<(), MonitorError> {
19        Self::stop(&self)?;
20        Self::start(&self, scale).await?;
21        Ok(())
22    }
23
24    /// Do a check of state.
25    async fn sync(&self) -> Result<(), MonitorError>;
26
27    /// Perform a health check on the monitor to ensure it is functioning correctly.
28    fn health_check() -> Result<(), MonitorError>;
29}
30
31#[derive(Debug, Error)]
32pub enum MonitorError {
33    /// Error indicating that the monitor failed to start due to a scale-related issue.
34    #[error("Wallet manager error: {0}")]
35    WalletManagerError(#[from] crate::wallet::WalletManagerError),
36
37    /// A custom error type for other errors, wrapped in a `Box` for dynamic dispatch.
38    #[error(transparent)]
39    Custom(#[from] Box<dyn std::error::Error + Send + Sync>),
40
41    /// Error indicating that the monitor is not currently running.
42    #[error("Monitor is not running")]
43    NotRunning,
44
45    /// Error indicating that the monitor's health check failed.
46    #[error("Monitor health check failed")]
47    HealthCheckFailed,
48}