prerefactor changes
parent
eda3a61acc
commit
90588b27d5
|
|
@ -1,7 +1,7 @@
|
||||||
// mod to communicate with api-grub config file
|
// mod to communicate with api-grub config file
|
||||||
// 1) check changes in unix-socket
|
// 1) check changes in unix-socket
|
||||||
// 2) save changes in local config file
|
// 2) save changes in local config file
|
||||||
use integr_structs::api::{ApiConfig, ApiConfigV2};
|
use integr_structs::api::ApiConfigV2;
|
||||||
use anyhow::{Error, Ok, Result};
|
use anyhow::{Error, Ok, Result};
|
||||||
use log::{info, warn, error};
|
use log::{info, warn, error};
|
||||||
use std::{fs, path::Path};
|
use std::{fs, path::Path};
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@ use deadpool_postgres::{Config, Pool, Runtime, Client as PgClient};
|
||||||
use tokio_postgres::NoTls;
|
use tokio_postgres::NoTls;
|
||||||
use dotenv::dotenv;
|
use dotenv::dotenv;
|
||||||
use std::env;
|
use std::env;
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
// type BufferType = Arc<Mutex<Vec<String>>>;
|
// type BufferType = Arc<Mutex<Vec<String>>>;
|
||||||
|
|
||||||
|
|
@ -107,6 +106,8 @@ impl<'a> ApiPoll<'a> {
|
||||||
let client = Arc::new(self.client.clone());
|
let client = Arc::new(self.client.clone());
|
||||||
let template = Arc::new(self.config.template.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
|
// TODO: rewrite nextly to async
|
||||||
for point in template.iter() {
|
for point in template.iter() {
|
||||||
let point = Arc::new(point.clone());
|
let point = Arc::new(point.clone());
|
||||||
|
|
@ -155,10 +156,12 @@ impl<'a> ApiPoll<'a> {
|
||||||
// buffer.push(text);
|
// buffer.push(text);
|
||||||
} else {
|
} else {
|
||||||
error!("{}: {} - Error with extracting text field from Response", &point.method.to_uppercase(), &point.url);
|
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(_) => {
|
Err(_) => {
|
||||||
error!("{}: {} endpoint is unreachable", &point.method.to_uppercase(), &point.url);
|
error!("{}: {} endpoint is unreachable", &point.method.to_uppercase(), &point.url);
|
||||||
|
return Err(Error::msg("Endpoint is unreachable"));
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
@ -254,7 +257,9 @@ mod net_unittests {
|
||||||
let mut poll = ApiPoll::new(&mut conf1).await;
|
let mut poll = ApiPoll::new(&mut conf1).await;
|
||||||
assert!(poll.process_polling(exporter.clone()).await.is_ok());
|
assert!(poll.process_polling(exporter.clone()).await.is_ok());
|
||||||
|
|
||||||
|
dbg!(&poll.config);
|
||||||
poll.change_config(conf2).await;
|
poll.change_config(conf2).await;
|
||||||
|
dbg!(&poll.config);
|
||||||
assert!(poll.process_polling(exporter.clone()).await.is_err());
|
assert!(poll.process_polling(exporter.clone()).await.is_err());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -27,7 +27,7 @@ impl Default for ApiConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
// v2
|
// v2
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug, PartialEq)]
|
||||||
pub struct ApiConfigV2 {
|
pub struct ApiConfigV2 {
|
||||||
pub id : u64,
|
pub id : u64,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
|
|
@ -90,7 +90,7 @@ impl ApiConfigV2 {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
|
||||||
pub struct Template {
|
pub struct Template {
|
||||||
pub id : String,
|
pub id : String,
|
||||||
pub name : String,
|
pub name : String,
|
||||||
|
|
@ -106,7 +106,7 @@ impl Default for Template {
|
||||||
id : String::from("no-id"),
|
id : String::from("no-id"),
|
||||||
name : String::from("no-name"),
|
name : String::from("no-name"),
|
||||||
url : String::from("no-url"),
|
url : String::from("no-url"),
|
||||||
method : String::from("no-method"),
|
method : String::from("post"),
|
||||||
measure : Vec::new(),
|
measure : Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue