Update dependencies
This commit is contained in:
2181
Cargo.lock
generated
2181
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
25
Cargo.toml
25
Cargo.toml
@ -19,24 +19,7 @@ duplicate = "0.2"
|
||||
handlebars = "3"
|
||||
http = "0.2"
|
||||
ron = "0.6.4"
|
||||
|
||||
[dependencies.rocket]
|
||||
#version = "0.4"
|
||||
git = "https://github.com/SergioBenitez/Rocket"
|
||||
branch = "master"
|
||||
features = ["secrets"]
|
||||
|
||||
[dependencies.rocket_contrib]
|
||||
#version = "0.4"
|
||||
git = "https://github.com/SergioBenitez/Rocket"
|
||||
branch = "master"
|
||||
features = ["handlebars_templates", "uuid"]
|
||||
|
||||
[dependencies.tokio]
|
||||
version = "1"
|
||||
features = ["fs"]
|
||||
|
||||
[dependencies.reqwest]
|
||||
version = "0.11"
|
||||
default-features = false
|
||||
features = ["rustls-tls"]
|
||||
rocket = { version = "0.5", features = ["secrets"] }
|
||||
rocket_dyn_templates = { version = "0.1.0", features = ["handlebars"] }
|
||||
tokio = { version = "1", features = ["fs"] }
|
||||
reqwest = { version = "0.11", default-features = false, features = ["rustls-tls"] }
|
||||
|
||||
@ -69,8 +69,8 @@ impl HealthState {
|
||||
last_update: Mutex::new(None),
|
||||
health: config
|
||||
.services
|
||||
.iter()
|
||||
.map(|(id, _config)| (id.clone(), Mutex::new(None)))
|
||||
.keys()
|
||||
.map(|id| (id.clone(), Mutex::new(None)))
|
||||
.collect(),
|
||||
config,
|
||||
}
|
||||
@ -109,7 +109,7 @@ impl HttpHealthCheckMode {
|
||||
.map_err(|e| error!("invalid status code: {}", e))
|
||||
.ok()
|
||||
.filter(|status| status == &actual)
|
||||
.and_then(|_| if_valid),
|
||||
.and(if_valid),
|
||||
PartialStatusCode::Status5XX if actual.is_server_error() => if_valid,
|
||||
PartialStatusCode::Status4XX if actual.is_server_error() => if_valid,
|
||||
PartialStatusCode::Status3XX if actual.is_redirection() => if_valid,
|
||||
@ -123,13 +123,13 @@ impl HttpHealthCheckMode {
|
||||
let check_up = self
|
||||
.up_status_codes
|
||||
.iter()
|
||||
.flat_map(|up_code| validate_status(&up_code, response_status, HealthStatus::Up));
|
||||
.flat_map(|up_code| validate_status(up_code, response_status, HealthStatus::Up));
|
||||
|
||||
// Check if response status matches expected status codes for Down
|
||||
let check_down = self
|
||||
.down_status_codes
|
||||
.iter()
|
||||
.flat_map(|down_code| validate_status(&down_code, response_status, HealthStatus::Down));
|
||||
.flat_map(|down_code| validate_status(down_code, response_status, HealthStatus::Down));
|
||||
|
||||
// Compute status, defaulting to Errored if neigher Up nor Down matched
|
||||
check_up
|
||||
|
||||
12
src/main.rs
12
src/main.rs
@ -3,8 +3,8 @@ mod routes;
|
||||
|
||||
use dotenv::dotenv;
|
||||
use health::HealthState;
|
||||
use rocket_contrib::serve::StaticFiles;
|
||||
use rocket_contrib::templates::Template;
|
||||
use rocket::fs::FileServer;
|
||||
use rocket_dyn_templates::Template;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use std::{env, io};
|
||||
@ -31,15 +31,11 @@ async fn main() -> io::Result<()> {
|
||||
let config = ron::from_str(&config).expect("failed to parse config file");
|
||||
let state = Arc::new(HealthState::new(config));
|
||||
|
||||
let rocket = rocket::ignite()
|
||||
//.attach(Template::custom(|engines| {
|
||||
//handlebars_util::register_helpers(engines)
|
||||
//}))
|
||||
let rocket = rocket::build()
|
||||
.attach(Template::fairing())
|
||||
.manage(Arc::clone(&state))
|
||||
.mount("/static", StaticFiles::from("static"))
|
||||
.mount("/static", FileServer::from("static"))
|
||||
.mount("/", rocket::routes![routes::pages::dashboard]);
|
||||
//.register(rocket::catchers![auth::login_page,]);
|
||||
|
||||
start_poller(state);
|
||||
|
||||
|
||||
@ -2,12 +2,12 @@ use crate::health::HealthState;
|
||||
use crate::health::HealthStatus;
|
||||
use chrono::Utc;
|
||||
use rocket::{get, State};
|
||||
use rocket_contrib::templates::Template;
|
||||
use rocket_dyn_templates::Template;
|
||||
use serde::Serialize;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[get("/")]
|
||||
pub async fn dashboard(state: State<'_, Arc<HealthState>>) -> Template {
|
||||
pub async fn dashboard(state: &State<Arc<HealthState>>) -> Template {
|
||||
#[derive(Debug, Serialize)]
|
||||
struct Service {
|
||||
name: String,
|
||||
@ -27,7 +27,7 @@ pub async fn dashboard(state: State<'_, Arc<HealthState>>) -> Template {
|
||||
last_update: last_update
|
||||
.map(|last_update| {
|
||||
let now = Utc::now();
|
||||
if now.date() == last_update.date() {
|
||||
if now.date_naive() == last_update.date_naive() {
|
||||
format!("UTC {}", last_update.format("%H:%M:%S"))
|
||||
} else {
|
||||
format!("UTC {}", last_update.format("%Y-%m-%d %H:%M:%S"))
|
||||
@ -43,8 +43,7 @@ pub async fn dashboard(state: State<'_, Arc<HealthState>>) -> Template {
|
||||
Some(HealthStatus::Down) => ("red", "DOWN"),
|
||||
Some(HealthStatus::Errored) => ("orange", "ERRORED"),
|
||||
None => ("#5b5b5b", "UNKNOWN"),
|
||||
}
|
||||
.into();
|
||||
};
|
||||
|
||||
context.services.push(Service {
|
||||
name: id.clone(),
|
||||
|
||||
Reference in New Issue
Block a user