use axum::http::StatusCode;
use redup_abstractions::Phase;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) struct ProbeOutcome {
status: StatusCode,
body: &'static str,
}
impl ProbeOutcome {
pub(crate) fn for_readiness(phase: Phase) -> Self {
match phase {
Phase::Serving => Self::success(),
_ => Self::failed(),
}
}
pub(crate) fn for_liveness(phase: Phase) -> Self {
match phase {
Phase::Failed => Self::failed(),
_ => Self::success(),
}
}
pub(crate) fn not_found() -> Self {
Self {
status: StatusCode::NOT_FOUND,
body: "Not found",
}
}
fn success() -> Self {
Self {
status: StatusCode::OK,
body: "Success",
}
}
fn failed() -> Self {
Self {
status: StatusCode::SERVICE_UNAVAILABLE,
body: "Failed",
}
}
pub(crate) fn status(self) -> StatusCode {
self.status
}
pub(crate) fn body(self) -> &'static str {
self.body
}
}