use uni_common::Result;
#[non_exhaustive]
pub enum WriteLease {
Local,
DynamoDB { table: String },
Custom(Box<dyn WriteLeaseProvider>),
}
pub struct LeaseGuard {
pub lease_id: String,
pub expires_at: chrono::DateTime<chrono::Utc>,
}
#[async_trait::async_trait]
pub trait WriteLeaseProvider: Send + Sync {
async fn acquire(&self) -> Result<LeaseGuard>;
async fn heartbeat(&self, guard: &LeaseGuard) -> Result<()>;
async fn release(&self, guard: LeaseGuard) -> Result<()>;
}
impl std::fmt::Debug for WriteLease {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
WriteLease::Local => write!(f, "WriteLease::Local"),
WriteLease::DynamoDB { table } => {
write!(f, "WriteLease::DynamoDB {{ table: {} }}", table)
}
WriteLease::Custom(_) => write!(f, "WriteLease::Custom(...)"),
}
}
}