feat: with monitor

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
2023-08-26 22:32:38 +02:00
parent 10eae9b36c
commit 569f5272e6
14 changed files with 526 additions and 95 deletions

View File

@@ -0,0 +1,57 @@
use std::sync::Arc;
use axum::{async_trait};
use tokio::sync::Mutex;
#[derive(Clone)]
pub struct LeaseService(Arc<dyn LeaseServiceTrait + Send + Sync + 'static>);
impl std::ops::Deref for LeaseService {
type Target = Arc<dyn LeaseServiceTrait + Send + Sync + 'static>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl Default for LeaseService {
fn default() -> Self {
Self(Arc::new(DefaultLeaseService::default()))
}
}
#[derive(Default)]
struct DefaultLeaseService {
leases: Arc<Mutex<Vec<String>>>,
}
#[async_trait]
pub trait LeaseServiceTrait {
async fn create_lease(&self) -> anyhow::Result<String>;
}
#[async_trait]
impl LeaseServiceTrait for DefaultLeaseService {
async fn create_lease(&self) -> anyhow::Result<String> {
let mut leases = self.leases.lock().await;
let lease = uuid::Uuid::new_v4().to_string();
leases.push(lease.clone());
Ok(lease)
}
}