use std::collections::HashMap;
use std::time::{SystemTime, UNIX_EPOCH};
pub fn epoch_ms() -> i64 {
SystemTime::now()
.duration_since(UNIX_EPOCH)
.expect("Time went backwards")
.as_millis() as i64
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Lease {
pub lease_key: String, pub owner: Option<String>, pub counter: i64, pub checkpoint: Option<String>, pub expires_at: i64, pub metadata: HashMap<String, String>, }
impl Lease {
pub fn is_expired(&self) -> bool {
epoch_ms() > self.expires_at + 2000
}
pub fn is_owned_by(&self, worker_id: &str) -> bool {
self.owner.as_deref() == Some(worker_id)
}
}