autopulse_service/settings/
opts.rs

1use autopulse_utils::Rotation;
2use serde::{Deserialize, Serialize};
3use std::path::PathBuf;
4
5#[doc(hidden)]
6const fn default_check_path() -> bool {
7    false
8}
9
10#[doc(hidden)]
11const fn default_max_retries() -> i32 {
12    5
13}
14
15#[doc(hidden)]
16const fn default_default_timer_wait() -> u64 {
17    60
18}
19
20#[doc(hidden)]
21const fn default_cleanup_days() -> u64 {
22    10
23}
24
25#[doc(hidden)]
26const fn default_webhook_retries() -> u8 {
27    3
28}
29
30#[doc(hidden)]
31const fn default_webhook_timeout() -> u64 {
32    10
33}
34
35#[doc(hidden)]
36const fn default_webhook_interval() -> u64 {
37    10
38}
39
40#[derive(Serialize, Clone, Deserialize, Default)]
41#[serde(rename_all = "lowercase")]
42pub enum LogRotation {
43    Daily,
44    Minutely,
45    Hourly,
46    #[default]
47    Never,
48}
49
50// impl Into<Rotation> for LogRotation {
51//     fn into(self) -> Rotation {
52//         match self {
53//             LogRotation::Daily => Rotation::DAILY,
54//             LogRotation::Minute => Rotation::MINUTELY,
55//             LogRotation::Hour => Rotation::HOURLY,
56//             LogRotation::Never => Rotation::NEVER,
57//         }
58//     }
59// }
60
61// from AutopulseRotation -> Rotation
62impl From<&LogRotation> for Rotation {
63    fn from(rotation: &LogRotation) -> Self {
64        match rotation {
65            LogRotation::Daily => Self::DAILY,
66            LogRotation::Minutely => Self::MINUTELY,
67            LogRotation::Hourly => Self::HOURLY,
68            LogRotation::Never => Self::NEVER,
69        }
70    }
71}
72
73#[derive(Serialize, Deserialize, Clone)]
74pub struct Opts {
75    /// Check if the path exists before processing (default: false)
76    #[serde(default = "default_check_path")]
77    pub check_path: bool,
78
79    /// Maximum retries before giving up (default: 5)
80    #[serde(default = "default_max_retries")]
81    pub max_retries: i32,
82
83    /// Default timer wait time (default: 60)
84    #[serde(default = "default_default_timer_wait")]
85    pub default_timer_wait: u64,
86
87    /// Cleanup not_found events older than x days (default: 10)
88    #[serde(default = "default_cleanup_days")]
89    pub cleanup_days: u64,
90
91    /// Log file path
92    pub log_file: Option<PathBuf>,
93
94    /// Whether to rollover the log file (default: never)
95    #[serde(default)]
96    pub log_file_rollover: LogRotation,
97
98    /// Number of retries for webhook HTTP requests (default: 3)
99    #[serde(default = "default_webhook_retries")]
100    pub webhook_retries: u8,
101
102    /// HTTP timeout in seconds for webhook requests (default: 10)
103    #[serde(default = "default_webhook_timeout")]
104    pub webhook_timeout: u64,
105
106    /// Interval in seconds between webhook batch sends (default: 10)
107    #[serde(default = "default_webhook_interval")]
108    pub webhook_interval: u64,
109}
110
111impl Default for Opts {
112    fn default() -> Self {
113        Self {
114            check_path: default_check_path(),
115            max_retries: default_max_retries(),
116            default_timer_wait: default_default_timer_wait(),
117            cleanup_days: default_cleanup_days(),
118            log_file: None,
119            log_file_rollover: LogRotation::default(),
120            webhook_retries: default_webhook_retries(),
121            webhook_timeout: default_webhook_timeout(),
122            webhook_interval: default_webhook_interval(),
123        }
124    }
125}