printobserver_core/config.rs
1//! What a running supervisor is configured with.
2
3use std::time::Duration;
4
5use crate::records::SafetyEnvelope;
6use printobserver_types::PrintId;
7
8/// The placeholder [`CoreConfig::context_command`] substitutes the print for.
9pub const PRINT_ID_PLACEHOLDER: &str = "{print_id}";
10
11/// How often the expiry driver looks for a bounded intervention that is due.
12pub const DEFAULT_EXPIRY_POLL: Duration = Duration::from_millis(250);
13
14/// How many of a print's own events a supervision turn is given.
15pub const DEFAULT_RECENT_EVENTS: u32 = 20;
16
17/// The server configuration supervision reads.
18#[derive(Debug, Clone, PartialEq)]
19pub struct CoreConfig {
20 /// The operator's safety envelope: what any actor may ask for at all.
21 pub envelope: SafetyEnvelope,
22 /// The command a supervision turn runs to read the print's context.
23 ///
24 /// [`PRINT_ID_PLACEHOLDER`] in it is replaced with the print's own
25 /// identifier, so that a turn reads the context of the print it is about.
26 pub context_command: String,
27 /// How many of the print's own events a turn is given, newest first.
28 pub recent_events: u32,
29 /// How often the expiry driver looks for an intervention that is due.
30 pub expiry_poll: Duration,
31}
32
33impl CoreConfig {
34 /// The configuration for one envelope, with this crate's own defaults.
35 #[must_use]
36 pub fn new(envelope: SafetyEnvelope, context_command: String) -> Self {
37 Self {
38 envelope,
39 context_command,
40 recent_events: DEFAULT_RECENT_EVENTS,
41 expiry_poll: DEFAULT_EXPIRY_POLL,
42 }
43 }
44
45 /// The context command for one print.
46 #[must_use]
47 pub fn context_command_for(&self, print_id: PrintId) -> String {
48 self.context_command
49 .replace(PRINT_ID_PLACEHOLDER, &print_id.to_string())
50 }
51}