From 90588b27d582634a117e9c0553be6ffa372e9aa6 Mon Sep 17 00:00:00 2001 From: prplV Date: Mon, 10 Feb 2025 13:21:42 +0300 Subject: [PATCH] prerefactor changes --- crates/api-grub/src/config.rs | 2 +- crates/api-grub/src/net.rs | 7 ++++++- crates/integr-structs/src/api.rs | 6 +++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/crates/api-grub/src/config.rs b/crates/api-grub/src/config.rs index f68e77e..11fe491 100644 --- a/crates/api-grub/src/config.rs +++ b/crates/api-grub/src/config.rs @@ -1,7 +1,7 @@ // mod to communicate with api-grub config file // 1) check changes in unix-socket // 2) save changes in local config file -use integr_structs::api::{ApiConfig, ApiConfigV2}; +use integr_structs::api::ApiConfigV2; use anyhow::{Error, Ok, Result}; use log::{info, warn, error}; use std::{fs, path::Path}; diff --git a/crates/api-grub/src/net.rs b/crates/api-grub/src/net.rs index e2580b2..b7b48bd 100644 --- a/crates/api-grub/src/net.rs +++ b/crates/api-grub/src/net.rs @@ -12,7 +12,6 @@ use deadpool_postgres::{Config, Pool, Runtime, Client as PgClient}; use tokio_postgres::NoTls; use dotenv::dotenv; use std::env; -use serde::{Deserialize, Serialize}; // type BufferType = Arc>>; @@ -107,6 +106,8 @@ impl<'a> ApiPoll<'a> { let client = Arc::new(self.client.clone()); let template = Arc::new(self.config.template.clone()); + if self.is_default().await { return Err(Error::msg("Default config with no endpoints")) } + // TODO: rewrite nextly to async for point in template.iter() { let point = Arc::new(point.clone()); @@ -155,10 +156,12 @@ impl<'a> ApiPoll<'a> { // buffer.push(text); } else { error!("{}: {} - Error with extracting text field from Response", &point.method.to_uppercase(), &point.url); + return Err(Error::msg("Error with extracting text field from Response")); } }, Err(_) => { error!("{}: {} endpoint is unreachable", &point.method.to_uppercase(), &point.url); + return Err(Error::msg("Endpoint is unreachable")); }, } Ok(()) @@ -254,7 +257,9 @@ mod net_unittests { let mut poll = ApiPoll::new(&mut conf1).await; assert!(poll.process_polling(exporter.clone()).await.is_ok()); + dbg!(&poll.config); poll.change_config(conf2).await; + dbg!(&poll.config); assert!(poll.process_polling(exporter.clone()).await.is_err()); } } \ No newline at end of file diff --git a/crates/integr-structs/src/api.rs b/crates/integr-structs/src/api.rs index de77a5e..c062da7 100644 --- a/crates/integr-structs/src/api.rs +++ b/crates/integr-structs/src/api.rs @@ -27,7 +27,7 @@ impl Default for ApiConfig { } // v2 -#[derive(Serialize, Deserialize, Debug)] +#[derive(Serialize, Deserialize, Debug, PartialEq)] pub struct ApiConfigV2 { pub id : u64, #[serde(default)] @@ -90,7 +90,7 @@ impl ApiConfigV2 { } -#[derive(Serialize, Deserialize, Debug, Clone)] +#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] pub struct Template { pub id : String, pub name : String, @@ -106,7 +106,7 @@ impl Default for Template { id : String::from("no-id"), name : String::from("no-name"), url : String::from("no-url"), - method : String::from("no-method"), + method : String::from("post"), measure : Vec::new(), } }