Compare commits

..

2 Commits

Author SHA1 Message Date
prplV 15bb446aa4 docs: hagent 2024-11-13 14:48:24 +03:00
prplV d58f140a29 docs: files 2024-11-13 14:42:31 +03:00
2 changed files with 78 additions and 2 deletions

View File

@ -7,6 +7,19 @@ use std::sync::Arc;
use tokio::sync::mpsc;
use tokio::time::Duration;
/// # Fn `create_watcher`
/// ## for creating watcher on file's delete | update events
///
/// *input* : `&str`, `&str`
///
/// *output* : `Err` if it cant create file watcher | `Ok(watcher)` on successfull construction
///
/// *initiator* : fn `file_handler`, fn `utils::run_daemons`
///
/// *managing* : current file's name: &str, path in local storage to current file: &str
///
/// *depends on* : -
///
pub async fn create_watcher(filename: &str, path: &str) -> Result<Inotify, std::io::Error> {
let src = format!("{}{}", path, filename);
let inotify: Inotify = Inotify::init()?;
@ -14,6 +27,19 @@ pub async fn create_watcher(filename: &str, path: &str) -> Result<Inotify, std::
Ok(inotify)
}
/// # Fn `create_watcher`
/// ## for managing processes by checking dep files' states
///
/// *input* : `&str`, `&[Files]`, `Arc<mpsc::Sender<u8>>`, `Arc<tokio::sync::Mutex<Vec<Inotify>>>`
///
/// *output* : `Err` if something with dep file is wrong | `Ok(())` on successfull dep file check
///
/// *initiator* : fn `utils::running_handler`
///
/// *managing* : current process's name: &str, list of dep files : `&[Files]`, atomic ref counter on sender main channel for current process `Arc<mpsc::Sender<u8>>`, mut list of file watchers`Arc<tokio::sync::Mutex<Vec<Inotify>>>`
///
/// *depends on* : Files
///
pub async fn file_handler(
name: &str,
files: &[Files],
@ -97,6 +123,19 @@ pub async fn file_handler(
Ok(())
}
/// # Fn `check_file`
/// ## for checking existance of current file
///
/// *input* : `&str`, `&str`
///
/// *output* : `Ok(())` if file exists | `Err(_)` if not | panic on fs error
///
/// *initiator* : fn `file_handler`
///
/// *managing* : current file's name: `&str` and current file's path in local storage: `&str`
///
/// *depends on* : network activity
///
pub async fn check_file(filename: &str, path: &str) -> Result<(), CustomError> {
let arc_name = Arc::new(filename.to_string());
let arc_path = Arc::new(path.to_string());

View File

@ -1,12 +1,37 @@
// module needed to check host-agent health condition and to communicate with it
/// asdasdasds
use tokio::{io::Interest, net::UnixStream};
/// # Fn `open_unix_socket`
/// ## opening unix-socket for host-agent communication
///
/// *input* : -
///
/// *output* : `Ok(socket)` if socket was successfully opened | `Err(er)` if not
///
/// *initiator* : main thread `(??)`
///
/// *managing* : -
///
/// *depends on* : -
///
async fn open_unix_socket() -> Result<UnixStream, std::io::Error> {
let socket = UnixStream::connect("/var/run/enode/hostagent.sock").await?;
Ok(socket)
}
/// # Fn `ha_healthcheck`
/// ## for checking host-agent state
///
/// *input* : `&UnixStream`
///
/// *output* : `Ok(()))` if host-agent is running | `Err(er)` if not
///
/// *initiator* : main thread `(??)`
///
/// *managing* : ref on unix-socket object
///
/// *depends on* : -
///
async fn ha_healthcheck(socket: &UnixStream) -> Result<(), std::io::Error >{
socket.ready(Interest::WRITABLE).await?;
if socket.writable().await.is_ok() {
@ -19,7 +44,19 @@ async fn ha_healthcheck(socket: &UnixStream) -> Result<(), std::io::Error >{
Ok(())
}
/// # Fn `ha_healthcheck`
/// ## for sending data to host-agent using unix-socket
///
/// *input* : `&UnixStream`, `&str`
///
/// *output* : `Ok(()))` if data was sent| `Err(er)` if not
///
/// *initiator* : main thread `(??)`
///
/// *managing* : socket: `&UnixStream`, data: `&str`
///
/// *depends on* : -
///
async fn ha_send_data(socket: &UnixStream, data: &str) -> Result<(), std::io::Error > {
socket.ready(Interest::WRITABLE).await?;
if socket.writable().await.is_ok() {