Skip to main content

autopulse_service/settings/
opts.rs

1use autopulse_utils::Rotation;
2use serde::{Deserialize, Serialize};
3use std::path::PathBuf;
4
5#[derive(Serialize, Clone, Deserialize, Default)]
6#[serde(rename_all = "lowercase")]
7pub enum LogRotation {
8    Daily,
9    Minutely,
10    Hourly,
11    #[default]
12    Never,
13}
14
15// impl Into<Rotation> for LogRotation {
16//     fn into(self) -> Rotation {
17//         match self {
18//             LogRotation::Daily => Rotation::DAILY,
19//             LogRotation::Minute => Rotation::MINUTELY,
20//             LogRotation::Hour => Rotation::HOURLY,
21//             LogRotation::Never => Rotation::NEVER,
22//         }
23//     }
24// }
25
26// from AutopulseRotation -> Rotation
27impl From<&LogRotation> for Rotation {
28    fn from(rotation: &LogRotation) -> Self {
29        match rotation {
30            LogRotation::Daily => Self::DAILY,
31            LogRotation::Minutely => Self::MINUTELY,
32            LogRotation::Hourly => Self::HOURLY,
33            LogRotation::Never => Self::NEVER,
34        }
35    }
36}
37
38#[derive(Serialize, Deserialize, Clone)]
39#[serde(default)]
40pub struct Opts {
41    /// Check if the path exists before processing (default: false)
42    pub check_path: bool,
43
44    /// Maximum retries before giving up (default: 5)
45    pub max_retries: i32,
46
47    /// Default timer wait time (default: 60)
48    pub default_timer_wait: u64,
49
50    /// Cleanup not_found events older than x days (default: 10)
51    pub cleanup_days: u64,
52
53    /// Log file path
54    pub log_file: Option<PathBuf>,
55
56    /// Whether to rollover the log file (default: never)
57    pub log_file_rollover: LogRotation,
58
59    /// Number of retries for webhook HTTP requests (default: 3)
60    pub webhook_retries: u8,
61
62    /// HTTP timeout in seconds for webhook requests (default: 10)
63    pub webhook_timeout: u64,
64
65    /// Interval in seconds between webhook batch sends (default: 10)
66    pub webhook_interval: u64,
67}
68
69impl Default for Opts {
70    fn default() -> Self {
71        Self {
72            check_path: false,
73            max_retries: 5,
74            default_timer_wait: 60,
75            cleanup_days: 10,
76            log_file: None,
77            log_file_rollover: LogRotation::default(),
78            webhook_retries: 3,
79            webhook_timeout: 10,
80            webhook_interval: 10,
81        }
82    }
83}