refactor: move system all modules to root

This commit is contained in:
Nikos Papadakis 2023-11-14 17:35:46 +02:00
parent 5c64f02579
commit 085e000009
Signed by untrusted user who does not match committer: nikos
GPG key ID: 78871F9905ADFF02
8 changed files with 17 additions and 22 deletions

View file

@ -52,8 +52,8 @@ impl Health {
/// # Usage /// # Usage
/// Internally it uses [Arc] so it can be cheaply cloned and shared. /// Internally it uses [Arc] so it can be cheaply cloned and shared.
/// ``` /// ```
/// use prymn_agent::system::health::HealthMonitor; /// use prymn_agent::health::HealthMonitor;
/// use prymn_agent::system::info::Info; /// use prymn_agent::info::Info;
/// ///
/// let mut info = Info::new(); /// let mut info = Info::new();
/// let health_monitor = HealthMonitor::new(); /// let health_monitor = HealthMonitor::new();

View file

@ -1,5 +1,7 @@
pub mod config; pub mod config;
pub mod debian; pub mod debian;
pub mod health;
pub mod info;
pub mod self_update; pub mod self_update;
pub mod server; pub mod server;
pub mod system; pub mod task;

View file

@ -7,10 +7,7 @@ use tokio_stream::{
use tokio_util::codec::{BytesCodec, FramedRead}; use tokio_util::codec::{BytesCodec, FramedRead};
use tonic::{Request, Response, Status}; use tonic::{Request, Response, Status};
use crate::{ use crate::{debian, health::HealthMonitor, info::Info, task::TaskBuilder};
debian,
system::{health::HealthMonitor, info::Info, task::TaskBuilder},
};
use super::proto::*; use super::proto::*;

View file

@ -4,17 +4,18 @@ use tokio::{signal, sync::oneshot};
use tower_http::trace::TraceLayer; use tower_http::trace::TraceLayer;
use crate::{ use crate::{
health::HealthMonitor,
info,
server::{agent::AgentService, proto::agent_server}, server::{agent::AgentService, proto::agent_server},
system::{self, health::HealthMonitor},
}; };
mod agent; mod agent;
mod proto { mod proto {
tonic::include_proto!("prymn"); tonic::include_proto!("prymn");
impl From<&crate::system::health::SystemHealth> for SystemHealth { impl From<&crate::health::SystemHealth> for SystemHealth {
fn from(val: &crate::system::health::SystemHealth) -> Self { fn from(val: &crate::health::SystemHealth) -> Self {
if let crate::system::health::SystemStatus::Critical(ref reasons) = val.status { if let crate::health::SystemStatus::Critical(ref reasons) = val.status {
SystemHealth { SystemHealth {
status: itertools::join(reasons.iter().map(ToString::to_string), ","), status: itertools::join(reasons.iter().map(ToString::to_string), ","),
} }
@ -26,8 +27,8 @@ mod proto {
} }
} }
impl From<&crate::system::task::TaskStatus> for TaskHealth { impl From<&crate::task::TaskStatus> for TaskHealth {
fn from(value: &crate::system::task::TaskStatus) -> Self { fn from(value: &crate::task::TaskStatus) -> Self {
Self { Self {
started_on: value.started_on().to_string(), started_on: value.started_on().to_string(),
progress: value.progress(), progress: value.progress(),
@ -35,8 +36,8 @@ mod proto {
} }
} }
impl From<&crate::system::info::Info> for SysInfoResponse { impl From<&crate::info::Info> for SysInfoResponse {
fn from(info: &crate::system::info::Info) -> Self { fn from(info: &crate::info::Info) -> Self {
use sysinfo::{CpuExt, DiskExt, SystemExt}; use sysinfo::{CpuExt, DiskExt, SystemExt};
let system = info.system(); let system = info.system();
@ -91,7 +92,7 @@ pub async fn run() -> anyhow::Result<()> {
let _ = shutdown_tx.send(()); let _ = shutdown_tx.send(());
}); });
let info = system::info::spawn_info_subsystem(); let info = info::spawn_info_subsystem();
let health_monitor = HealthMonitor::new(); let health_monitor = HealthMonitor::new();
// Monitor system info forever // Monitor system info forever

View file

@ -1,5 +0,0 @@
//! System boundary and modules that interact with the operating system and programs.
pub mod health;
pub mod info;
pub mod task;

View file

@ -1,4 +1,4 @@
use prymn_agent::system::{health::HealthMonitor, task::TaskBuilder}; use prymn_agent::{health::HealthMonitor, task::TaskBuilder};
#[tokio::test] #[tokio::test]
async fn task_is_gone_from_health_monitor_when_complete() { async fn task_is_gone_from_health_monitor_when_complete() {