jamjet_agents/
lifecycle.rs1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
5#[serde(rename_all = "snake_case")]
6pub enum AgentStatus {
7 Registered,
9 Active,
11 Paused,
13 Deactivated,
15 Archived,
17}
18
19impl AgentStatus {
20 pub fn can_accept_tasks(&self) -> bool {
21 matches!(self, Self::Active)
22 }
23
24 pub fn validate_transition(&self, next: &AgentStatus) -> Result<(), String> {
25 let valid = matches!(
26 (self, next),
27 (Self::Registered, Self::Active)
28 | (Self::Active, Self::Paused)
29 | (Self::Active, Self::Deactivated)
30 | (Self::Paused, Self::Active)
31 | (Self::Paused, Self::Deactivated)
32 | (Self::Deactivated, Self::Archived)
33 );
34 if valid {
35 Ok(())
36 } else {
37 Err(format!(
38 "invalid agent status transition: {self:?} → {next:?}"
39 ))
40 }
41 }
42}