prerefactor changes

pull/6/head
prplV 2025-02-10 13:21:42 +03:00
parent eda3a61acc
commit 90588b27d5
3 changed files with 10 additions and 5 deletions

View File

@ -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};

View File

@ -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<Mutex<Vec<String>>>;
@ -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());
}
}

View File

@ -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(),
}
}