refine sbot status pattern matching
This commit is contained in:
parent
7cdf8c553d
commit
7fe919d9a1
|
@ -8,7 +8,7 @@ use peach_lib::sbot::{SbotConfig, SbotStatus};
|
||||||
|
|
||||||
use crate::{error::PeachWebError, templates};
|
use crate::{error::PeachWebError, templates};
|
||||||
|
|
||||||
// HELPER FUNCTIONS
|
// SBOT HELPER FUNCTIONS
|
||||||
|
|
||||||
pub async fn init_sbot_with_config(
|
pub async fn init_sbot_with_config(
|
||||||
sbot_config: &Option<SbotConfig>,
|
sbot_config: &Option<SbotConfig>,
|
||||||
|
@ -47,6 +47,8 @@ fn latest_sequence_number() -> Result<u64, Box<dyn Error>> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HTML RENDERING FOR ELEMENTS
|
||||||
|
|
||||||
fn downtime_element(downtime: &Option<String>) -> Markup {
|
fn downtime_element(downtime: &Option<String>) -> Markup {
|
||||||
match downtime {
|
match downtime {
|
||||||
Some(time) => {
|
Some(time) => {
|
||||||
|
@ -185,59 +187,49 @@ fn render_status_elements<'a>() -> (
|
||||||
Markup,
|
Markup,
|
||||||
) {
|
) {
|
||||||
// retrieve go-sbot systemd process status
|
// retrieve go-sbot systemd process status
|
||||||
let sbot_status = SbotStatus::read();
|
match SbotStatus::read() {
|
||||||
|
Ok(status) if status.state == Some("active".to_string()) => (
|
||||||
// conditionally render the following elements:
|
"ACTIVE".to_string(),
|
||||||
// state, capsule border class, sbot icon class, uptime or downtime element,
|
"capsule capsule-container border-success",
|
||||||
// run on startup element and database (sequence number) element
|
"center icon icon-active",
|
||||||
if let Ok(status) = sbot_status {
|
uptime_element(&status.uptime),
|
||||||
match status.state {
|
run_on_startup_element(&status.boot_state),
|
||||||
Some(state) if state == "active" => (
|
database_element("active"),
|
||||||
"ACTIVE".to_string(),
|
memory_element(status.memory),
|
||||||
"capsule capsule-container border-success",
|
blobs_element(status.blobstore),
|
||||||
"center icon icon-active",
|
),
|
||||||
uptime_element(&status.uptime),
|
Ok(status) if status.state == Some("inactive".to_string()) => (
|
||||||
run_on_startup_element(&status.boot_state),
|
"INACTIVE".to_string(),
|
||||||
database_element("active"),
|
"capsule capsule-container border-warning",
|
||||||
memory_element(status.memory),
|
"center icon icon-inactive",
|
||||||
blobs_element(status.blobstore),
|
downtime_element(&status.downtime),
|
||||||
),
|
run_on_startup_element(&status.boot_state),
|
||||||
Some(state) if state == "inactive" => (
|
database_element("inactive"),
|
||||||
"INACTIVE".to_string(),
|
memory_element(None),
|
||||||
"capsule capsule-container border-warning",
|
blobs_element(status.blobstore),
|
||||||
"center icon icon-inactive",
|
),
|
||||||
downtime_element(&status.downtime),
|
// state is neither active nor inactive (might be "failed")
|
||||||
run_on_startup_element(&status.boot_state),
|
Ok(status) if status.state.is_some() => (
|
||||||
database_element("inactive"),
|
status.state.unwrap(),
|
||||||
memory_element(None),
|
"capsule capsule-container border-danger",
|
||||||
blobs_element(status.blobstore),
|
"center icon icon-inactive",
|
||||||
),
|
downtime_element(&None),
|
||||||
// state is neither active nor inactive (might be failed)
|
run_on_startup_element(&status.boot_state),
|
||||||
Some(state) => (
|
database_element("failed"),
|
||||||
state.to_string(),
|
memory_element(None),
|
||||||
"capsule capsule-container border-danger",
|
blobs_element(status.blobstore),
|
||||||
"center icon icon-inactive",
|
),
|
||||||
downtime_element(&None),
|
Ok(status) if status.state.is_none() => (
|
||||||
run_on_startup_element(&status.boot_state),
|
"UNAVAILABLE".to_string(),
|
||||||
database_element("failed"),
|
"capsule capsule-container border-danger",
|
||||||
memory_element(None),
|
"center icon icon-inactive",
|
||||||
blobs_element(status.blobstore),
|
downtime_element(&None),
|
||||||
),
|
run_on_startup_element(&status.boot_state),
|
||||||
None => (
|
database_element("unavailable"),
|
||||||
"UNAVAILABLE".to_string(),
|
memory_element(None),
|
||||||
"capsule capsule-container border-danger",
|
blobs_element(status.blobstore),
|
||||||
"center icon icon-inactive",
|
),
|
||||||
downtime_element(&None),
|
_ => (
|
||||||
run_on_startup_element(&status.boot_state),
|
|
||||||
database_element("unavailable"),
|
|
||||||
memory_element(None),
|
|
||||||
blobs_element(status.blobstore),
|
|
||||||
),
|
|
||||||
}
|
|
||||||
// show an error state if the attempt to read the go-sbot process
|
|
||||||
// status fails
|
|
||||||
} else {
|
|
||||||
(
|
|
||||||
"PROCESS QUERY FAILED".to_string(),
|
"PROCESS QUERY FAILED".to_string(),
|
||||||
"capsule capsule-container border-danger",
|
"capsule capsule-container border-danger",
|
||||||
"center icon icon-inactive",
|
"center icon icon-inactive",
|
||||||
|
@ -246,7 +238,7 @@ fn render_status_elements<'a>() -> (
|
||||||
database_element("error"),
|
database_element("error"),
|
||||||
memory_element(None),
|
memory_element(None),
|
||||||
blobs_element(None),
|
blobs_element(None),
|
||||||
)
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue