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