Skip to main content

tirea_agentos/runtime/
launch.rs

1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
2pub(crate) enum RunPersistence {
3    DurableRunRecord,
4    ThreadOnly,
5}
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8pub(crate) enum RunLineageMode {
9    Preserve,
10    Strip,
11}
12
13#[derive(Debug, Clone, Copy, PartialEq, Eq)]
14pub struct RunLaunchSpec {
15    persistence: RunPersistence,
16    lineage: RunLineageMode,
17}
18
19impl RunLaunchSpec {
20    pub const DURABLE: Self = Self::new(RunPersistence::DurableRunRecord, RunLineageMode::Preserve);
21
22    pub const TRANSIENT: Self = Self::new(RunPersistence::ThreadOnly, RunLineageMode::Preserve);
23
24    pub const DETACHED: Self = Self::new(RunPersistence::ThreadOnly, RunLineageMode::Strip);
25
26    pub const HTTP_RUN_API: Self = Self::DURABLE;
27    pub const HTTP_DIALOG: Self = Self::DETACHED;
28    pub const BACKGROUND_TASK: Self = Self::DURABLE;
29
30    pub(crate) const fn new(persistence: RunPersistence, lineage: RunLineageMode) -> Self {
31        Self {
32            persistence,
33            lineage,
34        }
35    }
36
37    pub(crate) const fn persist_run_mapping(self) -> bool {
38        matches!(self.persistence, RunPersistence::DurableRunRecord)
39    }
40
41    pub(crate) const fn strip_lineage(self) -> bool {
42        matches!(self.lineage, RunLineageMode::Strip)
43    }
44}
45
46#[cfg(test)]
47mod tests {
48    use super::*;
49
50    #[test]
51    fn http_dialog_is_thread_only_and_strips_lineage() {
52        assert!(!RunLaunchSpec::HTTP_DIALOG.persist_run_mapping());
53        assert!(RunLaunchSpec::HTTP_DIALOG.strip_lineage());
54    }
55
56    #[test]
57    fn background_task_is_durable_and_preserves_lineage() {
58        assert!(RunLaunchSpec::BACKGROUND_TASK.persist_run_mapping());
59        assert!(!RunLaunchSpec::BACKGROUND_TASK.strip_lineage());
60    }
61}