Skip to main content

solti_core/state/
config.rs

1//! # State configuration.
2//!
3//! [`StateConfig`] controls TTLs and sweep interval for [`TaskState`](super::TaskState).
4
5use std::time::Duration;
6
7/// Configuration for in-memory state retention and periodic sweep.
8///
9/// | Parameter        | Controls                                                    | Default     |
10/// |------------------|-------------------------------------------------------------|-------------|
11/// | `run_ttl`        | How long finished runs are retained before sweep removes them | 1 hour    |
12/// | `task_ttl`       | How long terminal tasks (no active runs) are retained         | 1 hour    |
13/// | `sweep_interval` | How often the sweep runs                                      | 5 minutes |
14///
15/// ## Also
16///
17/// - `TaskState::sweep` consumes these TTL settings.
18/// - [`SupervisorApi::new`](crate::SupervisorApi::new) accepts this config and auto-starts the sweep task.
19#[derive(Debug, Clone)]
20pub struct StateConfig {
21    /// How long to keep completed runs before sweep removes them.
22    pub run_ttl: Duration,
23    /// How long to keep tasks in a terminal phase (with no active runs) before sweep removes them.
24    pub task_ttl: Duration,
25    /// How often the sweep embedded task runs.
26    pub sweep_interval: Duration,
27}
28
29impl Default for StateConfig {
30    fn default() -> Self {
31        Self {
32            run_ttl: Duration::from_secs(3_600),
33            task_ttl: Duration::from_secs(3_600),
34            sweep_interval: Duration::from_secs(300),
35        }
36    }
37}