2026-09-03 12:46:14 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
|
|
|
|
#[serde(rename_all = "snake_case")]
|
|
|
|
|
pub enum RunStatus {
|
|
|
|
|
Queued,
|
|
|
|
|
Leased,
|
|
|
|
|
Running,
|
|
|
|
|
WaitingInput,
|
|
|
|
|
WaitingTakeover,
|
|
|
|
|
Completed,
|
|
|
|
|
Failed,
|
|
|
|
|
Cancelled,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl RunStatus {
|
|
|
|
|
pub fn as_str(self) -> &'static str {
|
|
|
|
|
match self {
|
|
|
|
|
Self::Queued => "queued",
|
|
|
|
|
Self::Leased => "leased",
|
|
|
|
|
Self::Running => "running",
|
|
|
|
|
Self::WaitingInput => "waiting_input",
|
|
|
|
|
Self::WaitingTakeover => "waiting_takeover",
|
|
|
|
|
Self::Completed => "completed",
|
|
|
|
|
Self::Failed => "failed",
|
|
|
|
|
Self::Cancelled => "cancelled",
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn is_active(self) -> bool {
|
|
|
|
|
matches!(
|
|
|
|
|
self,
|
2026-09-04 09:08:56 +00:00
|
|
|
Self::Queued
|
|
|
|
|
| Self::Leased
|
|
|
|
|
| Self::Running
|
|
|
|
|
| Self::WaitingInput
|
|
|
|
|
| Self::WaitingTakeover
|
2026-09-03 12:46:14 +00:00
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn is_terminal(self) -> bool {
|
|
|
|
|
matches!(self, Self::Completed | Self::Failed | Self::Cancelled)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn can_transition(self, to: Self) -> bool {
|
|
|
|
|
matches!(
|
|
|
|
|
(self, to),
|
|
|
|
|
(Self::Queued, Self::Leased | Self::Cancelled)
|
|
|
|
|
| (Self::Leased, Self::Running | Self::Queued | Self::Cancelled)
|
|
|
|
|
| (
|
|
|
|
|
Self::Running,
|
|
|
|
|
Self::WaitingInput
|
|
|
|
|
| Self::WaitingTakeover
|
|
|
|
|
| Self::Completed
|
|
|
|
|
| Self::Failed
|
|
|
|
|
| Self::Cancelled
|
|
|
|
|
| Self::Leased
|
|
|
|
|
)
|
2026-09-04 09:08:56 +00:00
|
|
|
| (
|
|
|
|
|
Self::WaitingInput,
|
|
|
|
|
Self::Queued | Self::Leased | Self::Cancelled
|
|
|
|
|
)
|
|
|
|
|
| (
|
|
|
|
|
Self::WaitingTakeover,
|
|
|
|
|
Self::Queued | Self::Leased | Self::Cancelled
|
|
|
|
|
)
|
2026-09-03 12:46:14 +00:00
|
|
|
| (Self::Failed, Self::Queued)
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub const ACTIVE_RUN_STATUSES: &[RunStatus] = &[
|
|
|
|
|
RunStatus::Queued,
|
|
|
|
|
RunStatus::Leased,
|
|
|
|
|
RunStatus::Running,
|
|
|
|
|
RunStatus::WaitingInput,
|
|
|
|
|
RunStatus::WaitingTakeover,
|
|
|
|
|
];
|