global refactoring - gathering in modules and setting up for tests
parent
8056f594a4
commit
7e521a20c5
|
|
@ -0,0 +1,2 @@
|
||||||
|
pub mod options;
|
||||||
|
pub mod utils;
|
||||||
25
src/main.rs
25
src/main.rs
|
|
@ -1,19 +1,13 @@
|
||||||
mod config;
|
mod options;
|
||||||
mod files;
|
|
||||||
mod logger;
|
|
||||||
mod prcs;
|
|
||||||
mod services;
|
|
||||||
mod signals;
|
|
||||||
mod structs;
|
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
use config::*;
|
|
||||||
use log::{error, info};
|
use log::{error, info};
|
||||||
use logger::setup_logger;
|
use options::config::*;
|
||||||
use signals::set_valid_destructor;
|
use options::logger::setup_logger;
|
||||||
|
use options::signals::set_valid_destructor;
|
||||||
|
use options::structs::*;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use structs::*;
|
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
use utils::*;
|
use utils::*;
|
||||||
|
|
||||||
|
|
@ -71,9 +65,9 @@ async fn main() {
|
||||||
handler.push(tokio::spawn(async move {
|
handler.push(tokio::spawn(async move {
|
||||||
if set_valid_destructor(Arc::new(senders)).await.is_err() {
|
if set_valid_destructor(Arc::new(senders)).await.is_err() {
|
||||||
error!("Linux signals handler creation failed. Terminating main thread...");
|
error!("Linux signals handler creation failed. Terminating main thread...");
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
// todo: rework this temp construction, use async/await in signals mod
|
|
||||||
tokio::time::sleep(Duration::from_millis(200)).await;
|
tokio::time::sleep(Duration::from_millis(200)).await;
|
||||||
info!("End of job. Terminating main thread...");
|
info!("End of job. Terminating main thread...");
|
||||||
std::process::exit(0);
|
std::process::exit(0);
|
||||||
|
|
@ -89,3 +83,8 @@ async fn main() {
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// todo: integration tests
|
||||||
|
// todo: config pulling mechanism rework (socket)
|
||||||
|
// todo: tasks management after killing all processes
|
||||||
|
// todo:
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
// ! gathering optional items module
|
||||||
|
|
||||||
|
pub mod config;
|
||||||
|
pub mod logger;
|
||||||
|
pub mod signals;
|
||||||
|
pub mod structs;
|
||||||
|
|
@ -1,11 +1,10 @@
|
||||||
use crate::structs::*;
|
use crate::options::structs::*;
|
||||||
use log::{error, info, warn};
|
use log::{error, info, warn};
|
||||||
use redis::{Client, Commands, Connection, RedisResult};
|
use redis::{Client, Commands, Connection, RedisResult};
|
||||||
use std::os::unix::process::CommandExt;
|
use std::os::unix::process::CommandExt;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::{env, fs};
|
use std::{env, fs};
|
||||||
use std::fmt::format;
|
|
||||||
use tokio::time::Duration;
|
use tokio::time::Duration;
|
||||||
|
|
||||||
const CONFIG_PATH: &str = "settings.json";
|
const CONFIG_PATH: &str = "settings.json";
|
||||||
|
|
@ -30,7 +29,9 @@ pub fn get_actual_config() -> Option<Processes> {
|
||||||
"Found local configuration, version - {}",
|
"Found local configuration, version - {}",
|
||||||
&local_conf.date_of_creation
|
&local_conf.date_of_creation
|
||||||
);
|
);
|
||||||
if let Some(remote_conf) = once_get_remote_configuration(&format!("redis://{}/", local_conf.config_server)) {
|
if let Some(remote_conf) =
|
||||||
|
once_get_remote_configuration(&format!("redis://{}/", local_conf.config_server))
|
||||||
|
{
|
||||||
return match config_comparing(&local_conf, &remote_conf) {
|
return match config_comparing(&local_conf, &remote_conf) {
|
||||||
ConfigActuality::Local => {
|
ConfigActuality::Local => {
|
||||||
info!("Local config is actual");
|
info!("Local config is actual");
|
||||||
|
|
@ -13,7 +13,7 @@ use crate::utils::get_container_id;
|
||||||
// file_writer: BufWriter<File>,
|
// file_writer: BufWriter<File>,
|
||||||
// }
|
// }
|
||||||
|
|
||||||
pub fn setup_logger() -> Result<(), crate::structs::CustomError> {
|
pub fn setup_logger() -> Result<(), crate::options::structs::CustomError> {
|
||||||
// if Command::new("sh").args(["-c", "mkdir logs"]).output().is_err() {
|
// if Command::new("sh").args(["-c", "mkdir logs"]).output().is_err() {
|
||||||
// println!("Error: Cannot init logs directory");
|
// println!("Error: Cannot init logs directory");
|
||||||
// std::process::exit(1);
|
// std::process::exit(1);
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::structs::CustomError;
|
use crate::options::structs::CustomError;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::io;
|
use tokio::io;
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
27
src/utils.rs
27
src/utils.rs
|
|
@ -1,13 +1,17 @@
|
||||||
use crate::files::create_watcher;
|
pub mod files;
|
||||||
use crate::files::file_handler;
|
pub mod prcs;
|
||||||
use crate::prcs::{
|
pub mod services;
|
||||||
|
|
||||||
|
use crate::options::structs::TrackingProcess;
|
||||||
|
use files::create_watcher;
|
||||||
|
use files::file_handler;
|
||||||
|
use inotify::Inotify;
|
||||||
|
use log::{error, warn};
|
||||||
|
use prcs::{
|
||||||
freeze_process, is_active, is_frozen, restart_process, start_process, terminate_process,
|
freeze_process, is_active, is_frozen, restart_process, start_process, terminate_process,
|
||||||
unfreeze_process,
|
unfreeze_process,
|
||||||
};
|
};
|
||||||
use crate::services::service_handler;
|
use services::service_handler;
|
||||||
use crate::structs::TrackingProcess;
|
|
||||||
use inotify::Inotify;
|
|
||||||
use log::{error, warn};
|
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::join;
|
use tokio::join;
|
||||||
|
|
@ -189,10 +193,13 @@ pub fn get_container_id() -> Option<String> {
|
||||||
}
|
}
|
||||||
let id = String::from_utf8_lossy(&output.stdout).to_string();
|
let id = String::from_utf8_lossy(&output.stdout).to_string();
|
||||||
if id.is_empty() {
|
if id.is_empty() {
|
||||||
return None
|
return None;
|
||||||
}
|
}
|
||||||
Some(String::from_utf8_lossy(&output.stdout).to_string())
|
Some(String::from_utf8_lossy(&output.stdout).to_string())
|
||||||
},
|
}
|
||||||
Err(er) => { println!("failed( : {}", er); None },
|
Err(er) => {
|
||||||
|
println!("failed( : {}", er);
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::prcs::{is_active, is_frozen};
|
use crate::options::structs::{CustomError, Files};
|
||||||
use crate::structs::{CustomError, Files};
|
use crate::utils::prcs::{is_active, is_frozen};
|
||||||
use inotify::{EventMask, Inotify, WatchMask};
|
use inotify::{EventMask, Inotify, WatchMask};
|
||||||
use log::error;
|
use log::error;
|
||||||
use std::borrow::BorrowMut;
|
use std::borrow::BorrowMut;
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::structs::CustomError;
|
use crate::options::structs::CustomError;
|
||||||
use log::{error, warn};
|
use log::{error, warn};
|
||||||
use std::process::{Command, Output};
|
use std::process::{Command, Output};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::prcs::{is_active, is_frozen};
|
use crate::options::structs::{CustomError, Services};
|
||||||
use crate::structs::{CustomError, Services};
|
use crate::utils::prcs::{is_active, is_frozen};
|
||||||
use log::{error, warn};
|
use log::{error, warn};
|
||||||
use std::net::{TcpStream, ToSocketAddrs};
|
use std::net::{TcpStream, ToSocketAddrs};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
{
|
||||||
|
"dateOfCreation": "1721381809103",
|
||||||
|
"configServer" : "localhost",
|
||||||
|
"processes": [
|
||||||
|
{
|
||||||
|
"name": "temp-process",
|
||||||
|
"path": "/home/vladislav/web/runner-rs/examples/",
|
||||||
|
"dependencies": {
|
||||||
|
"files": [
|
||||||
|
{
|
||||||
|
"filename": "dep-file",
|
||||||
|
"src": "/home/vladislav/web/runner-rs/examples/",
|
||||||
|
"triggers": {
|
||||||
|
"onDelete": "hold",
|
||||||
|
"onChange": "stop"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"services": [
|
||||||
|
{
|
||||||
|
"hostname": "localhost",
|
||||||
|
"port": 8080,
|
||||||
|
"triggers": {
|
||||||
|
"wait": 10,
|
||||||
|
"delay": 2,
|
||||||
|
"onLost": "stop"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
use runner_rs::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test() {
|
||||||
|
assert_eq!(2, 2);
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue