Skip to main content

remem/db/
extraction_task_kind.rs

1use anyhow::{bail, Result};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq)]
4pub enum ExtractionTaskKind {
5    CapturedGitLink,
6    SessionRollup,
7    ObservationExtract,
8    MemoryCandidate,
9    UserContextCandidate,
10    GraphCandidate,
11    RuleCandidate,
12    IndexUpdate,
13}
14
15impl ExtractionTaskKind {
16    pub fn as_str(self) -> &'static str {
17        match self {
18            Self::CapturedGitLink => "captured_git_link",
19            Self::SessionRollup => "session_rollup",
20            Self::ObservationExtract => "observation_extract",
21            Self::MemoryCandidate => "memory_candidate",
22            Self::UserContextCandidate => "user_context_candidate",
23            Self::GraphCandidate => "graph_candidate",
24            Self::RuleCandidate => "rule_candidate",
25            Self::IndexUpdate => "index_update",
26        }
27    }
28
29    pub fn from_db(raw: &str) -> Result<Self> {
30        match raw {
31            "captured_git_link" => Ok(Self::CapturedGitLink),
32            "session_rollup" => Ok(Self::SessionRollup),
33            "observation_extract" => Ok(Self::ObservationExtract),
34            "memory_candidate" => Ok(Self::MemoryCandidate),
35            "user_context_candidate" => Ok(Self::UserContextCandidate),
36            "graph_candidate" => Ok(Self::GraphCandidate),
37            "rule_candidate" => Ok(Self::RuleCandidate),
38            "index_update" => Ok(Self::IndexUpdate),
39            _ => bail!("unknown extraction task kind: {raw}"),
40        }
41    }
42
43    pub(crate) fn priority(self) -> i64 {
44        match self {
45            Self::CapturedGitLink => 5,
46            Self::SessionRollup => 10,
47            Self::ObservationExtract => 20,
48            Self::UserContextCandidate => 30,
49            Self::MemoryCandidate => 40,
50            Self::GraphCandidate => 50,
51            Self::RuleCandidate => 60,
52            Self::IndexUpdate => 80,
53        }
54    }
55}