Skip to main content

execra/runtime/
config.rs

1use std::path::PathBuf;
2use std::time::Duration;
3
4#[derive(Debug, Clone)]
5pub struct Config {
6    pub db_path: PathBuf,
7    pub log_dir: PathBuf,
8    pub raw_output: RawOutputPolicy,
9    pub retention: RetentionPolicy,
10    pub max_concurrent: usize,
11    pub default_grace_period: Duration,
12}
13
14impl Default for Config {
15    fn default() -> Self {
16        Config {
17            db_path: PathBuf::from("execra.db"),
18            log_dir: PathBuf::from("execra-logs"),
19            raw_output: RawOutputPolicy::Persist,
20            retention: RetentionPolicy::default(),
21            max_concurrent: std::thread::available_parallelism()
22                .map(|n| n.get())
23                .unwrap_or(4),
24            default_grace_period: Duration::from_secs(5),
25        }
26    }
27}
28
29#[derive(Debug, Clone, Copy, PartialEq, Eq)]
30pub enum RawOutputPolicy {
31    Persist,
32    #[cfg(feature = "gzip")]
33    PersistGzipOnFinalize,
34    MemoryOnly,
35    Disabled,
36}
37
38#[derive(Debug, Clone)]
39pub struct RetentionPolicy {
40    pub keep_events_for: Duration,
41    pub keep_raw_for: Duration,
42    pub pinned_tag: String,
43}
44
45impl Default for RetentionPolicy {
46    fn default() -> Self {
47        RetentionPolicy {
48            keep_events_for: Duration::from_secs(60 * 60 * 24 * 30),
49            keep_raw_for: Duration::from_secs(60 * 60 * 24 * 7),
50            pinned_tag: "pinned".into(),
51        }
52    }
53}