appcore_contracts/policy/
health.rs1use super::*;
12
13#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
15pub struct HealthRequirements {
16 startup_grace_ms: u64,
17 heartbeat_interval_ms: u64,
18 failure_threshold: u32,
19}
20
21impl HealthRequirements {
22 pub fn new(
24 startup_grace_ms: u64,
25 heartbeat_interval_ms: u64,
26 failure_threshold: u32,
27 ) -> ContractResult<Self> {
28 if heartbeat_interval_ms == 0 || failure_threshold == 0 {
29 return Err(ContractError::InvalidValue {
30 field: "health",
31 reason: "heartbeat interval and failure threshold must be greater than zero",
32 });
33 }
34 Ok(Self {
35 startup_grace_ms,
36 heartbeat_interval_ms,
37 failure_threshold,
38 })
39 }
40
41 pub fn startup_grace_ms(&self) -> u64 {
43 self.startup_grace_ms
44 }
45
46 pub fn heartbeat_interval_ms(&self) -> u64 {
48 self.heartbeat_interval_ms
49 }
50
51 pub fn failure_threshold(&self) -> u32 {
53 self.failure_threshold
54 }
55
56 pub(crate) fn validate(&self) -> ContractResult<()> {
57 if self.heartbeat_interval_ms == 0 || self.failure_threshold == 0 {
58 return Err(ContractError::InvalidValue {
59 field: "health",
60 reason: "heartbeat interval and failure threshold must be greater than zero",
61 });
62 }
63 Ok(())
64 }
65}