actionqueue_engine/lease/
model.rs1use actionqueue_core::ids::RunId;
9
10#[derive(Debug, Clone, PartialEq, Eq, Hash, Ord, PartialOrd)]
12pub struct LeaseOwner(String);
13
14impl LeaseOwner {
15 pub fn new(owner: impl Into<String>) -> Self {
19 let value = owner.into();
20 assert!(!value.is_empty(), "LeaseOwner must not be empty");
21 Self(value)
22 }
23
24 pub fn as_str(&self) -> &str {
26 &self.0
27 }
28}
29
30impl std::fmt::Display for LeaseOwner {
31 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
32 write!(f, "{}", self.0)
33 }
34}
35
36impl From<String> for LeaseOwner {
37 fn from(value: String) -> Self {
38 Self::new(value)
39 }
40}
41
42impl From<&str> for LeaseOwner {
43 fn from(value: &str) -> Self {
44 Self::new(value.to_owned())
45 }
46}
47
48#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd)]
50pub struct LeaseExpiry {
51 expires_at: u64,
53}
54
55impl LeaseExpiry {
56 pub const fn at(expires_at: u64) -> Self {
58 Self { expires_at }
59 }
60
61 pub const fn expires_at(&self) -> u64 {
63 self.expires_at
64 }
65}
66
67#[derive(Debug, Clone, PartialEq, Eq)]
69pub struct Lease {
70 run_id: RunId,
72
73 owner: LeaseOwner,
75
76 expiry: LeaseExpiry,
78}
79
80impl Lease {
81 pub fn new(run_id: RunId, owner: LeaseOwner, expiry: LeaseExpiry) -> Self {
83 Self { run_id, owner, expiry }
84 }
85
86 pub fn run_id(&self) -> RunId {
88 self.run_id
89 }
90
91 pub fn owner(&self) -> &LeaseOwner {
93 &self.owner
94 }
95
96 pub fn expiry(&self) -> LeaseExpiry {
98 self.expiry
99 }
100}