appcore_contracts/policy/
job.rs1use super::*;
12
13#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
15pub struct JobPolicy {
16 enabled: bool,
17 max_concurrency: u32,
18 retry_limit: u32,
19}
20
21impl JobPolicy {
22 pub fn new(enabled: bool, max_concurrency: u32, retry_limit: u32) -> ContractResult<Self> {
24 if enabled && max_concurrency == 0 {
25 return Err(ContractError::InvalidValue {
26 field: "jobs.max_concurrency",
27 reason: "must be greater than zero when jobs are enabled",
28 });
29 }
30 Ok(Self {
31 enabled,
32 max_concurrency,
33 retry_limit,
34 })
35 }
36
37 pub fn disabled() -> Self {
39 Self {
40 enabled: false,
41 max_concurrency: 0,
42 retry_limit: 0,
43 }
44 }
45
46 pub fn is_enabled(&self) -> bool {
48 self.enabled
49 }
50
51 pub fn max_concurrency(&self) -> u32 {
53 self.max_concurrency
54 }
55
56 pub fn retry_limit(&self) -> u32 {
58 self.retry_limit
59 }
60
61 pub(crate) fn validate(&self) -> ContractResult<()> {
62 if self.enabled && self.max_concurrency == 0 {
63 return Err(ContractError::InvalidValue {
64 field: "jobs.max_concurrency",
65 reason: "must be greater than zero when jobs are enabled",
66 });
67 }
68 Ok(())
69 }
70}