#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ServiceHealth {
Ready,
Healthy,
Degraded,
Failed,
Starting,
Stopping,
Unknown,
}
impl ServiceHealth {
pub fn dependency_ready(self) -> bool {
matches!(self, Self::Ready | Self::Healthy | Self::Degraded)
}
pub fn is_failed(self) -> bool {
self == Self::Failed
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ServiceActivationState {
Enabled,
Disabled,
NotConfigured,
}
impl ServiceActivationState {
pub fn is_enabled(self) -> bool {
self == Self::Enabled
}
pub fn is_configured(self) -> bool {
self != Self::NotConfigured
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ServiceRuntimeState {
Starting,
Running,
StopRequested,
Stopping,
Stopped,
RestartScheduled,
Restarting,
Orphaned,
Quarantined,
Failed,
}
impl ServiceRuntimeState {
pub fn owns_resource(self) -> bool {
matches!(
self,
Self::Starting
| Self::Running
| Self::StopRequested
| Self::Stopping
| Self::Restarting
| Self::Orphaned
)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DependencyRequirement {
Ready,
Healthy,
DegradedAllowed,
Optional,
}
impl DependencyRequirement {
pub fn accepts(self, health: ServiceHealth) -> bool {
match self {
Self::Ready => matches!(health, ServiceHealth::Ready | ServiceHealth::Healthy),
Self::Healthy => health == ServiceHealth::Healthy,
Self::DegradedAllowed => health.dependency_ready(),
Self::Optional => true,
}
}
}