use std::fmt;
use std::str::FromStr;
use crate::error::JammiError;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ResultTableStatus {
Building,
Ready,
Failed,
}
impl fmt::Display for ResultTableStatus {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Building => write!(f, "building"),
Self::Ready => write!(f, "ready"),
Self::Failed => write!(f, "failed"),
}
}
}
impl FromStr for ResultTableStatus {
type Err = JammiError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"building" => Ok(Self::Building),
"ready" => Ok(Self::Ready),
"failed" => Ok(Self::Failed),
other => Err(JammiError::Catalog(format!(
"Unknown result table status: '{other}'"
))),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TrainingJobStatus {
Queued,
Running,
Completed,
Failed,
}
impl fmt::Display for TrainingJobStatus {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Queued => write!(f, "queued"),
Self::Running => write!(f, "running"),
Self::Completed => write!(f, "completed"),
Self::Failed => write!(f, "failed"),
}
}
}
impl FromStr for TrainingJobStatus {
type Err = JammiError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"queued" => Ok(Self::Queued),
"running" => Ok(Self::Running),
"completed" => Ok(Self::Completed),
"failed" => Ok(Self::Failed),
other => Err(JammiError::Catalog(format!(
"Unknown training job status: '{other}'"
))),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum EvalRunStatus {
Completed,
}
impl fmt::Display for EvalRunStatus {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Completed => write!(f, "completed"),
}
}
}
impl FromStr for EvalRunStatus {
type Err = JammiError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"completed" => Ok(Self::Completed),
other => Err(JammiError::Catalog(format!(
"Unknown eval run status: '{other}'"
))),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ModelStatus {
Registered,
Loaded,
Retired,
}
impl fmt::Display for ModelStatus {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Registered => write!(f, "registered"),
Self::Loaded => write!(f, "loaded"),
Self::Retired => write!(f, "retired"),
}
}
}
impl FromStr for ModelStatus {
type Err = JammiError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"registered" => Ok(Self::Registered),
"loaded" => Ok(Self::Loaded),
"retired" => Ok(Self::Retired),
other => Err(JammiError::Catalog(format!(
"Unknown model status: '{other}'"
))),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn model_status_round_trips_through_display_and_from_str() {
for status in [
ModelStatus::Registered,
ModelStatus::Loaded,
ModelStatus::Retired,
] {
let rendered = status.to_string();
let parsed = ModelStatus::from_str(&rendered).expect("canonical status parses");
assert_eq!(parsed, status, "round-trip must be identity for {status:?}");
}
assert_eq!(ModelStatus::Retired.to_string(), "retired");
assert!(ModelStatus::from_str("available").is_err());
}
}