autopulse_service/settings/
opts.rs

1use autopulse_utils::Rotation;
2use serde::Deserialize;
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#[derive(Clone, Deserialize, Default)]
26#[serde(rename_all = "lowercase")]
27pub enum LogRotation {
28    Daily,
29    Minutely,
30    Hourly,
31    #[default]
32    Never,
33}
34
35// impl Into<Rotation> for LogRotation {
36//     fn into(self) -> Rotation {
37//         match self {
38//             LogRotation::Daily => Rotation::DAILY,
39//             LogRotation::Minute => Rotation::MINUTELY,
40//             LogRotation::Hour => Rotation::HOURLY,
41//             LogRotation::Never => Rotation::NEVER,
42//         }
43//     }
44// }
45
46// from AutopulseRotation -> Rotation
47impl From<LogRotation> for Rotation {
48    fn from(rotation: LogRotation) -> Self {
49        match rotation {
50            LogRotation::Daily => Self::DAILY,
51            LogRotation::Minutely => Self::MINUTELY,
52            LogRotation::Hourly => Self::HOURLY,
53            LogRotation::Never => Self::NEVER,
54        }
55    }
56}
57
58#[derive(Deserialize, Clone)]
59pub struct Opts {
60    /// Check if the path exists before processing (default: false)
61    #[serde(default = "default_check_path")]
62    pub check_path: bool,
63
64    /// Maximum retries before giving up (default: 5)
65    #[serde(default = "default_max_retries")]
66    pub max_retries: i32,
67
68    /// Default timer wait time (default: 60)
69    #[serde(default = "default_default_timer_wait")]
70    pub default_timer_wait: u64,
71
72    /// Cleanup events older than x days (default: 10)
73    #[serde(default = "default_cleanup_days")]
74    pub cleanup_days: u64,
75
76    /// Log file path
77    pub log_file: Option<PathBuf>,
78
79    /// Whether to rollover the log file (default: never)
80    #[serde(default)]
81    pub log_file_rollover: LogRotation,
82}
83
84impl Default for Opts {
85    fn default() -> Self {
86        Self {
87            check_path: default_check_path(),
88            max_retries: default_max_retries(),
89            default_timer_wait: default_default_timer_wait(),
90            cleanup_days: default_cleanup_days(),
91            log_file: None,
92            log_file_rollover: LogRotation::default(),
93        }
94    }
95}