#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum ServerStatus {
Starting,
Running,
Failed,
Retrying,
Shutdown,
ShuttingDown,
Stopped,
}
impl Default for ServerStatus {
fn default() -> Self {
Self::Stopped
}
}
impl ServerStatus {
pub fn shutdown_requested(&self) -> bool {
matches!(self, Self::Shutdown | Self::ShuttingDown)
}
pub(crate) fn can_start(&self) -> bool {
matches!(self, Self::Stopped | Self::Retrying)
}
pub fn can_reconfigure(&self) -> bool {
matches!(self, Self::Stopped | Self::Failed)
}
pub fn description(&self) -> &'static str {
match self {
Self::Starting => "Server is starting up",
Self::Running => "Server is running and accepting connections",
Self::Failed => "Server failed to start",
Self::Retrying => "Server is waiting to retry startup",
Self::Shutdown => "Server is shutting down gracefully",
Self::ShuttingDown => "Server is in the process of shutting down",
Self::Stopped => "Server is stopped",
}
}
pub fn is_terminal(&self) -> bool {
matches!(self, Self::Stopped | Self::Failed)
}
}