From 2767b875b810beaf35cf2112df9e08675a43dd62 Mon Sep 17 00:00:00 2001 From: Maksim Ryndin Date: Sat, 24 Feb 2024 17:41:41 +0000 Subject: [PATCH] refactoring --- CHANGELOG.md | 8 +- src/{spreadsheet => google}/datavalue.rs | 4 +- src/{spreadsheet => google}/mod.rs | 1 - src/{spreadsheet => google}/sheet.rs | 2 +- src/{spreadsheet => google}/spreadsheet.rs | 10 +- src/lib.rs | 140 ++------------------- src/main.rs | 2 +- src/notifications.rs | 126 +++++++++++++++++++ src/rules/mod.rs | 6 +- src/services/general/mod.rs | 69 +++++----- src/services/healthcheck/mod.rs | 5 +- src/services/kv/mod.rs | 14 ++- src/services/logs/mod.rs | 7 +- src/services/metrics/mod.rs | 5 +- src/services/mod.rs | 15 +-- src/services/system/collector.rs | 4 +- src/services/system/mod.rs | 9 +- src/storage.rs | 21 ++-- 18 files changed, 231 insertions(+), 217 deletions(-) rename src/{spreadsheet => google}/datavalue.rs (99%) rename src/{spreadsheet => google}/mod.rs (98%) rename src/{spreadsheet => google}/sheet.rs (99%) rename src/{spreadsheet => google}/spreadsheet.rs (99%) create mode 100644 src/notifications.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 165258e..65381fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,8 @@ -* 0.1.4 - * releases for other platforms - * fine grained notifications control - * installer shell scripts - * 0.1.3 * fix version message for telegram + * releases for other platforms + * fine grained notifications control + * installer shell script * 0.1.2 * improve an append error handling and reporting diff --git a/src/spreadsheet/datavalue.rs b/src/google/datavalue.rs similarity index 99% rename from src/spreadsheet/datavalue.rs rename to src/google/datavalue.rs index c645dc0..3880b5e 100644 --- a/src/spreadsheet/datavalue.rs +++ b/src/google/datavalue.rs @@ -1,6 +1,6 @@ +use crate::google::sheet::{str_to_id, Header, SheetId}; +use crate::google::{DEFAULT_FONT, DEFAULT_FONT_TEXT}; use crate::rules::RuleApplicant; -use crate::spreadsheet::sheet::{str_to_id, Header, SheetId}; -use crate::spreadsheet::{DEFAULT_FONT, DEFAULT_FONT_TEXT}; use chrono::{NaiveDate, NaiveDateTime, NaiveTime}; use google_sheets4::api::{ CellData, CellFormat, Color, ColorStyle, ExtendedValue, NumberFormat, RowData, TextFormat, diff --git a/src/spreadsheet/mod.rs b/src/google/mod.rs similarity index 98% rename from src/spreadsheet/mod.rs rename to src/google/mod.rs index 51a28b3..7e5f2a9 100644 --- a/src/spreadsheet/mod.rs +++ b/src/google/mod.rs @@ -1,6 +1,5 @@ pub mod datavalue; pub mod sheet; -#[allow(clippy::module_inception)] pub mod spreadsheet; use crate::HyperConnector; use google_sheets4::oauth2; diff --git a/src/spreadsheet/sheet.rs b/src/google/sheet.rs similarity index 99% rename from src/spreadsheet/sheet.rs rename to src/google/sheet.rs index 50a7b85..c945a9d 100644 --- a/src/spreadsheet/sheet.rs +++ b/src/google/sheet.rs @@ -1,4 +1,4 @@ -use crate::spreadsheet::{Metadata, DEFAULT_FONT}; +use crate::google::{Metadata, DEFAULT_FONT}; use google_sheets4::api::Sheet as GoogleSheet; use google_sheets4::api::{ AddSheetRequest, AppendCellsRequest, BasicFilter, BooleanCondition, CellData, CellFormat, diff --git a/src/spreadsheet/spreadsheet.rs b/src/google/spreadsheet.rs similarity index 99% rename from src/spreadsheet/spreadsheet.rs rename to src/google/spreadsheet.rs index e143bfb..1ceff1e 100644 --- a/src/spreadsheet/spreadsheet.rs +++ b/src/google/spreadsheet.rs @@ -1,10 +1,10 @@ -use crate::spreadsheet::sheet::{CleanupSheet, Rows, Sheet, SheetId, UpdateSheet, VirtualSheet}; -use crate::spreadsheet::Metadata; +use crate::google::sheet::{CleanupSheet, Rows, Sheet, SheetId, UpdateSheet, VirtualSheet}; +use crate::google::Metadata; use crate::storage::StorageError; +use crate::notifications::Sender; #[cfg(not(test))] use crate::HyperConnector; -use crate::Sender; use chrono::Utc; use google_sheets4::api::{ BatchUpdateSpreadsheetRequest, BatchUpdateSpreadsheetResponse, Spreadsheet, @@ -25,7 +25,7 @@ use http::response::Response; use serde_json::Value; #[cfg(test)] -use crate::spreadsheet::spreadsheet::tests::TestState; +use crate::google::spreadsheet::tests::TestState; // https://support.google.com/docs/thread/181288162/whats-the-maximum-amount-of-rows-in-google-sheets?hl=en pub(crate) const GOOGLE_SPREADSHEET_MAXIMUM_CELLS: u64 = 10_000_000; @@ -342,7 +342,7 @@ impl SpreadsheetAPI { #[cfg(test)] pub(crate) mod tests { use super::*; - use crate::spreadsheet::sheet::tests::mock_sheet_with_properties; + use crate::google::sheet::tests::mock_sheet_with_properties; use google_sheets4::api::Sheet as GoogleSheet; use google_sheets4::api::{ AddSheetRequest, AppendCellsRequest, BasicFilter, CreateDeveloperMetadataRequest, diff --git a/src/lib.rs b/src/lib.rs index aa2848c..05cd8cd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,16 +1,19 @@ pub mod configuration; +pub mod google; pub mod messenger; +pub mod notifications; pub mod rules; pub mod services; -pub mod spreadsheet; pub mod storage; -use crate::messenger::configuration::MessengerConfig; use chrono::{DateTime, NaiveDateTime, Utc}; pub use configuration::*; +use google::sheet::TabColorRGB; +pub use google::*; use google_sheets4::hyper_rustls::HttpsConnector; use hyper::{client::connect::HttpConnector, Client}; use lazy_static::lazy_static; pub use messenger::*; +pub use notifications::*; use regex::Regex; use services::general::{GeneralService, GENERAL_SERVICE_NAME}; use services::healthcheck::{HealthcheckService, HEALTHCHECK_SERVICE_NAME}; @@ -19,16 +22,13 @@ use services::logs::{LogsService, LOGS_SERVICE_NAME}; use services::metrics::{MetricsService, METRICS_SERVICE_NAME}; use services::system::{SystemService, SYSTEM_SERVICE_NAME}; pub use services::*; -use spreadsheet::sheet::TabColorRGB; -pub use spreadsheet::*; use std::collections::HashMap; use std::fmt::{self, Debug}; use std::sync::Arc; use std::time::Duration; pub use storage::*; use sysinfo::System; -use tokio::sync::mpsc::{self, error::TrySendError, Receiver, Sender as TokioSender}; -use tracing::Level; +use tokio::sync::mpsc::Receiver; pub(crate) type HyperConnector = HttpsConnector; pub(crate) type HttpsClient = Client; @@ -123,7 +123,7 @@ pub fn collect_services( config: Configuration, shared: Shared, mut messengers: HashMap<&'static str, Option>>, - channel: Receiver, + channel: Receiver, ) -> Vec> { let mut services = Vec::with_capacity(5); let assertion = @@ -194,134 +194,14 @@ pub fn collect_services( services } -#[derive(Debug)] -pub struct Notification { - pub(crate) message: String, - pub(crate) level: Level, -} - -impl Notification { - pub(crate) fn new(message: String, level: Level) -> Self { - Self { message, level } - } -} - -#[derive(Debug, Clone)] -pub struct Sender { - tx: TokioSender, - service: &'static str, -} - -impl Sender { - pub fn new(tx: TokioSender, service: &'static str) -> Self { - Self { tx, service } - } - - pub async fn send(&self, notification: Notification) { - if self.tx.send(notification).await.is_err() { - panic!( - "failed to send notification - `{}` service doesn't accept notifications", - self.service - ); - } - } - - pub fn send_nonblock(&self, notification: Notification) { - match self.tx.try_send(notification) { - Err(TrySendError::Closed(_)) => { - panic!( - "failed to send notification - `{}` service doesn't accept notifications", - self.service - ) - } - Err(TrySendError::Full(n)) => { - tracing::error!( - "failed to send notification {:?} - `{}` service notifications queue is full", - n, - self.service - ); - } - Ok(_) => (), - } - } - - pub async fn info(&self, message: String) { - let notification = Notification::new(message, Level::INFO); - self.send(notification).await - } - - pub fn try_info(&self, message: String) { - let notification = Notification::new(message, Level::INFO); - self.send_nonblock(notification) - } - - pub async fn warn(&self, message: String) { - let notification = Notification::new(message, Level::WARN); - self.send(notification).await - } - - pub fn try_warn(&self, message: String) { - let notification = Notification::new(message, Level::WARN); - self.send_nonblock(notification) - } - - pub async fn error(&self, message: String) { - let notification = Notification::new(message, Level::ERROR); - self.send(notification).await - } - - pub fn try_error(&self, message: String) { - let notification = Notification::new(message, Level::ERROR); - self.send_nonblock(notification) - } - - pub async fn fatal(&self, message: String) { - let notification = Notification::new(message, Level::ERROR); - self.send(notification).await; - // for fatal errors we need some time to send error - // It is more important to notify user via messenger than to - // restart quickly because restart doesn't help for recovery - // user is required to fix a problem - tokio::time::sleep(Duration::from_millis(500)).await; - } -} - -pub(crate) fn setup_messenger_channel(service: &'static str) -> (Sender, Receiver) { - let (tx, rx) = mpsc::channel(60); // 60 simultaneous messages is enough for any rate limiting messenger - let tx = Sender::new(tx, service); - (tx, rx) -} - -pub fn setup_general_messenger_channel() -> (Sender, Receiver) { - setup_messenger_channel(GENERAL_SERVICE_NAME) -} - -#[derive(Debug)] -pub(crate) struct MessengerApi { - pub(crate) config: MessengerConfig, - pub(crate) message_tx: Sender, - pub(crate) message_rx: Option>, -} - -impl MessengerApi { - fn new(config: MessengerConfig, service: &'static str) -> Self { - let (message_tx, message_rx) = setup_messenger_channel(service); - Self { - config, - message_tx, - message_rx: Some(message_rx), - } - } -} - #[derive(Clone)] pub struct Shared { pub(crate) messenger: Option>, - pub(crate) send_notification: Sender, + pub(crate) send_notification: notifications::Sender, } impl Shared { - pub fn new(send_notification: Sender) -> Shared { + pub fn new(send_notification: notifications::Sender) -> Shared { Self { messenger: None, send_notification, @@ -342,7 +222,7 @@ impl Debug for Shared { } pub async fn welcome( - send_notification: Sender, + send_notification: notifications::Sender, project_id: String, truncation_check: Result<(), String>, ) { diff --git a/src/main.rs b/src/main.rs index d8b90a6..d13ba35 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,7 @@ use clap::Parser; use futures::future::try_join_all; use goral::configuration::{Configuration, APP_NAME}; -use goral::spreadsheet::{get_google_auth, SpreadsheetAPI}; +use goral::google::{get_google_auth, SpreadsheetAPI}; use goral::storage::{AppendableLog, Storage}; use goral::{ collect_messengers, collect_services, setup_general_messenger_channel, welcome, Shared, diff --git a/src/notifications.rs b/src/notifications.rs new file mode 100644 index 0000000..a790124 --- /dev/null +++ b/src/notifications.rs @@ -0,0 +1,126 @@ +use crate::messenger::configuration::MessengerConfig; +use crate::services::general::GENERAL_SERVICE_NAME; +use std::fmt::Debug; +use std::time::Duration; +use tokio::sync::mpsc::{self, error::TrySendError, Receiver, Sender as TokioSender}; +use tracing::Level; + +#[derive(Debug)] +pub struct Notification { + pub(crate) message: String, + pub(crate) level: Level, +} + +impl Notification { + pub(crate) fn new(message: String, level: Level) -> Self { + Self { message, level } + } +} + +#[derive(Debug, Clone)] +pub struct Sender { + tx: TokioSender, + service: &'static str, +} + +impl Sender { + pub fn new(tx: TokioSender, service: &'static str) -> Self { + Self { tx, service } + } + + pub async fn send(&self, notification: Notification) { + if self.tx.send(notification).await.is_err() { + panic!( + "failed to send notification - `{}` service doesn't accept notifications", + self.service + ); + } + } + + pub fn send_nonblock(&self, notification: Notification) { + match self.tx.try_send(notification) { + Err(TrySendError::Closed(_)) => { + panic!( + "failed to send notification - `{}` service doesn't accept notifications", + self.service + ) + } + Err(TrySendError::Full(n)) => { + tracing::error!( + "failed to send notification {:?} - `{}` service notifications queue is full", + n, + self.service + ); + } + Ok(_) => (), + } + } + + pub async fn info(&self, message: String) { + let notification = Notification::new(message, Level::INFO); + self.send(notification).await + } + + pub fn try_info(&self, message: String) { + let notification = Notification::new(message, Level::INFO); + self.send_nonblock(notification) + } + + pub async fn warn(&self, message: String) { + let notification = Notification::new(message, Level::WARN); + self.send(notification).await + } + + pub fn try_warn(&self, message: String) { + let notification = Notification::new(message, Level::WARN); + self.send_nonblock(notification) + } + + pub async fn error(&self, message: String) { + let notification = Notification::new(message, Level::ERROR); + self.send(notification).await + } + + pub fn try_error(&self, message: String) { + let notification = Notification::new(message, Level::ERROR); + self.send_nonblock(notification) + } + + pub async fn fatal(&self, message: String) { + let notification = Notification::new(message, Level::ERROR); + self.send(notification).await; + // for fatal errors we need some time to send error + // It is more important to notify user via messenger than to + // restart quickly because restart doesn't help for recovery + // user is required to fix a problem + tokio::time::sleep(Duration::from_millis(500)).await; + } +} + +pub(crate) fn setup_messenger_channel(service: &'static str) -> (Sender, Receiver) { + let (tx, rx) = mpsc::channel(60); // 60 simultaneous messages is enough for any rate limiting messenger + let tx = Sender::new(tx, service); + (tx, rx) +} + +pub fn setup_general_messenger_channel() -> (Sender, Receiver) { + setup_messenger_channel(GENERAL_SERVICE_NAME) +} + +#[derive(Debug)] +pub(crate) struct MessengerApi { + pub(crate) config: MessengerConfig, + pub(crate) message_tx: Sender, + pub(crate) message_rx: Option>, +} + +impl MessengerApi { + pub(crate) fn new(config: MessengerConfig, service: &'static str) -> Self { + let (message_tx, message_rx) = setup_messenger_channel(service); + Self { + config, + message_tx, + message_rx: Some(message_rx), + } + } +} diff --git a/src/rules/mod.rs b/src/rules/mod.rs index eb8f2f9..7c2a3b7 100644 --- a/src/rules/mod.rs +++ b/src/rules/mod.rs @@ -1,6 +1,6 @@ -use crate::spreadsheet::datavalue::{Datarow, Datavalue, NOT_AVAILABLE}; -use crate::spreadsheet::sheet::{Dropdown, SheetId}; -use crate::{Notification, Sender}; +use crate::google::datavalue::{Datarow, Datavalue, NOT_AVAILABLE}; +use crate::google::sheet::{Dropdown, SheetId}; +use crate::notifications::{Notification, Sender}; use chrono::Utc; use serde_json::Value; use std::collections::HashMap; diff --git a/src/services/general/mod.rs b/src/services/general/mod.rs index 796eb60..6d9584b 100644 --- a/src/services/general/mod.rs +++ b/src/services/general/mod.rs @@ -3,11 +3,12 @@ pub(crate) mod configuration; use crate::configuration::APP_NAME; use crate::messenger::configuration::MessengerConfig; use crate::messenger::BoxedMessenger; +use crate::notifications::{Notification, Sender}; use crate::services::general::configuration::General; use crate::services::http_client::HttpClient; use crate::services::Service; use crate::storage::AppendableLog; -use crate::{Notification, Shared}; +use crate::Shared; use async_trait::async_trait; use serde::Deserialize; use std::fmt::Debug; @@ -34,6 +35,35 @@ async fn latest_release() -> Result { + let release = latest_release().await; + match release { + Ok(release) => { + let current = env!("CARGO_PKG_VERSION"); + let latest = release.tag_name; + if !release.prerelease && current != latest { + let msg = format!( + "Your `{APP_NAME}` version `{current}` is not the latest `{latest}`, \ + consider [upgrading](https://github.com/maksimryndin/goral/releases); \ + if you like `{APP_NAME}`, consider giving a star to the [repo](https://github.com/maksimryndin/goral); \ + thank you😊" + ); + send_notification.info(msg).await; + } + }, + Err(e) => { + tracing::error!("error {} when fetching the latest {} release", e, APP_NAME); + } + } + } + } + } +} + #[derive(Debug)] pub(crate) struct GeneralService { shared: Shared, @@ -121,35 +151,7 @@ impl Service for GeneralService { let send_notification = self.shared().send_notification.clone(); let collect = self.collect_notifications(log.host_id()); tokio::pin!(collect); // pin and pass by mutable ref to prevent cancelling this future by select! - let release_checker = tokio::spawn(async move { - let mut release_check_interval = - tokio::time::interval(Duration::from_secs(60 * 60 * 24 * 3)); - loop { - tokio::select! { - _ = release_check_interval.tick() => { - let release = latest_release().await; - match release { - Ok(release) => { - let current = env!("CARGO_PKG_VERSION"); - let latest = release.tag_name; - if !release.prerelease && current != latest { - let msg = format!( - "Your `{APP_NAME}` version `{current}` is not the latest `{latest}`, \ - consider [upgrading](https://github.com/maksimryndin/goral/releases); \ - if you like `{APP_NAME}`, consider giving a star to the [repo](https://github.com/maksimryndin/goral); \ - thank you😊" - ); - send_notification.info(msg).await; - } - }, - Err(e) => { - tracing::error!("error {} when fetching the latest {} release", e, APP_NAME); - } - } - } - } - } - }); + let release_checker = tokio::spawn(release_check(send_notification)); tokio::pin!(release_checker); tokio::select! { @@ -181,12 +183,13 @@ impl Service for GeneralService { mod tests { use super::*; use crate::configuration::tests::build_config; + use crate::google::spreadsheet::tests::TestState; + use crate::google::spreadsheet::SpreadsheetAPI; use crate::messenger::tests::TestMessenger; - use crate::spreadsheet::spreadsheet::tests::TestState; - use crate::spreadsheet::spreadsheet::SpreadsheetAPI; + use crate::notifications::Sender; use crate::storage::Storage; use crate::tests::TEST_HOST_ID; - use crate::{Sender, Shared}; + use crate::Shared; use std::sync::{ atomic::{AtomicUsize, Ordering}, Arc, diff --git a/src/services/healthcheck/mod.rs b/src/services/healthcheck/mod.rs index 38bc80e..fe6b0b9 100644 --- a/src/services/healthcheck/mod.rs +++ b/src/services/healthcheck/mod.rs @@ -1,15 +1,16 @@ pub(crate) mod configuration; use crate::configuration::APP_NAME; +use crate::google::datavalue::{Datarow, Datavalue}; use crate::messenger::configuration::MessengerConfig; +use crate::notifications::{MessengerApi, Notification, Sender}; use crate::services::healthcheck::configuration::{ scrape_push_rule, Healthcheck, Liveness as LivenessConfig, LivenessType, }; use crate::services::http_client::HttpClient; use crate::services::{Data, Service, TaskResult}; -use crate::spreadsheet::datavalue::{Datarow, Datavalue}; use crate::storage::AppendableLog; -use crate::{MessengerApi, Notification, Sender, Shared}; +use crate::Shared; use async_trait::async_trait; use chrono::{DateTime, Utc}; diff --git a/src/services/kv/mod.rs b/src/services/kv/mod.rs index 2196189..1b724fd 100644 --- a/src/services/kv/mod.rs +++ b/src/services/kv/mod.rs @@ -1,11 +1,12 @@ pub(crate) mod configuration; +use crate::google::datavalue::{Datarow, Datavalue}; use crate::messenger::configuration::MessengerConfig; +use crate::notifications::{MessengerApi, Notification, Sender}; use crate::rules::RULES_LOG_NAME; use crate::services::kv::configuration::Kv; use crate::services::{messenger_queue, rules_notifications, Data, Service}; -use crate::spreadsheet::datavalue::{Datarow, Datavalue}; use crate::storage::{AppendableLog, StorageError}; -use crate::{capture_datetime, MessengerApi, Notification, Sender, Shared}; +use crate::{capture_datetime, Shared}; use async_trait::async_trait; use chrono::{DateTime, NaiveDateTime, Utc}; use futures::future::try_join_all; @@ -435,12 +436,13 @@ impl Service for KvService { mod tests { use super::*; use crate::configuration::tests::build_config; - use crate::spreadsheet::spreadsheet::tests::TestState; - use crate::spreadsheet::spreadsheet::SpreadsheetAPI; - use crate::spreadsheet::Metadata; + use crate::google::spreadsheet::tests::TestState; + use crate::google::spreadsheet::SpreadsheetAPI; + use crate::google::Metadata; + use crate::notifications::Sender; use crate::storage::Storage; use crate::tests::TEST_HOST_ID; - use crate::{Sender, Shared}; + use crate::Shared; use hyper::{header, Body, Client, Method}; use serde_json::json; use std::sync::Arc; diff --git a/src/services/logs/mod.rs b/src/services/logs/mod.rs index af7ef40..b1aba6e 100644 --- a/src/services/logs/mod.rs +++ b/src/services/logs/mod.rs @@ -1,12 +1,13 @@ pub(crate) mod configuration; +use crate::google::datavalue::{Datarow, Datavalue}; +use crate::google::spreadsheet::GOOGLE_SPREADSHEET_MAXIMUM_CHARS_PER_CELL; use crate::messenger::configuration::MessengerConfig; +use crate::notifications::{MessengerApi, Notification, Sender}; use crate::rules::{Action, Rule, RuleCondition}; use crate::services::logs::configuration::{channel_capacity, Logs}; use crate::services::{Data, Service, TaskResult}; -use crate::spreadsheet::datavalue::{Datarow, Datavalue}; -use crate::spreadsheet::spreadsheet::GOOGLE_SPREADSHEET_MAXIMUM_CHARS_PER_CELL; use crate::storage::AppendableLog; -use crate::{capture_datetime, MessengerApi, Notification, Sender, Shared}; +use crate::{capture_datetime, Shared}; use async_trait::async_trait; use chrono::{Duration as ChronoDuration, NaiveDateTime, Utc}; use lazy_static::lazy_static; diff --git a/src/services/metrics/mod.rs b/src/services/metrics/mod.rs index 017183c..5a628fa 100644 --- a/src/services/metrics/mod.rs +++ b/src/services/metrics/mod.rs @@ -1,12 +1,13 @@ pub(crate) mod configuration; +use crate::google::datavalue::{Datarow, Datavalue}; use crate::messenger::configuration::MessengerConfig; +use crate::notifications::{MessengerApi, Notification, Sender}; use crate::services::http_client::HttpClient; use crate::services::metrics::configuration::{scrape_push_rule, Metrics}; use crate::services::{Data, Service, TaskResult}; -use crate::spreadsheet::datavalue::{Datarow, Datavalue}; use crate::storage::AppendableLog; -use crate::{MessengerApi, Notification, Sender, Shared}; +use crate::Shared; use async_trait::async_trait; use chrono::{DateTime, Utc}; diff --git a/src/services/mod.rs b/src/services/mod.rs index bce2b10..dee62ad 100644 --- a/src/services/mod.rs +++ b/src/services/mod.rs @@ -6,11 +6,12 @@ pub(crate) mod logs; pub(crate) mod metrics; pub(crate) mod system; +use crate::google::datavalue::{Datarow, Datavalue}; use crate::messenger::configuration::MessengerConfig; +use crate::notifications::{Notification, Sender}; use crate::rules::{Action, Rule, RuleCondition, RuleOutput, Triggered}; -use crate::spreadsheet::datavalue::{Datarow, Datavalue}; use crate::storage::AppendableLog; -use crate::{jitter_duration, BoxedMessenger, Notification, Sender, Shared}; +use crate::{jitter_duration, BoxedMessenger, Shared}; use async_trait::async_trait; use futures::future::try_join_all; use std::sync::{ @@ -607,14 +608,14 @@ pub trait Service: Send + Sync { mod tests { use super::*; use crate::configuration::ceiled_division; + use crate::google::datavalue::Datavalue; + use crate::google::spreadsheet::tests::TestState; + use crate::google::spreadsheet::SpreadsheetAPI; + use crate::google::Metadata; + use crate::notifications::Sender; use crate::services::general::GENERAL_SERVICE_NAME; - use crate::spreadsheet::datavalue::Datavalue; - use crate::spreadsheet::spreadsheet::tests::TestState; - use crate::spreadsheet::spreadsheet::SpreadsheetAPI; - use crate::spreadsheet::Metadata; use crate::storage::Storage; use crate::tests::TEST_HOST_ID; - use crate::Sender; use chrono::Utc; diff --git a/src/services/system/collector.rs b/src/services/system/collector.rs index f8bbaca..574ddef 100644 --- a/src/services/system/collector.rs +++ b/src/services/system/collector.rs @@ -1,5 +1,5 @@ -use crate::spreadsheet::datavalue::{Datarow, Datavalue}; -use crate::{Notification, Sender}; +use crate::google::datavalue::{Datarow, Datavalue}; +use crate::notifications::{Notification, Sender}; use chrono::NaiveDateTime; use std::path::Path; use std::thread; diff --git a/src/services/system/mod.rs b/src/services/system/mod.rs index f398491..351c733 100644 --- a/src/services/system/mod.rs +++ b/src/services/system/mod.rs @@ -1,12 +1,13 @@ pub(crate) mod collector; pub(crate) mod configuration; +use crate::google::datavalue::{Datarow, Datavalue}; use crate::messenger::configuration::MessengerConfig; +use crate::notifications::{MessengerApi, Notification, Sender}; use crate::rules::{Action, Rule, RuleCondition}; use crate::services::system::configuration::{scrape_push_rule, System}; use crate::services::{Data, Service, TaskResult}; -use crate::spreadsheet::datavalue::{Datarow, Datavalue}; use crate::storage::AppendableLog; -use crate::{MessengerApi, Notification, Sender, Shared}; +use crate::Shared; use async_trait::async_trait; use chrono::{DateTime, Utc}; use std::sync::{ @@ -302,8 +303,8 @@ impl Service for SystemService { #[cfg(test)] mod tests { use super::*; - use crate::spreadsheet::datavalue::Datavalue; - use crate::Notification; + use crate::google::datavalue::Datavalue; + use crate::notifications::Notification; use tracing::Level; #[tokio::test] diff --git a/src/storage.rs b/src/storage.rs index 09ae1e1..5b0db04 100644 --- a/src/storage.rs +++ b/src/storage.rs @@ -1,11 +1,12 @@ -use crate::rules::{rules_dropdowns, Rule, RULES_LOG_NAME}; -use crate::spreadsheet::datavalue::Datarow; -use crate::spreadsheet::sheet::{ +use crate::google::datavalue::Datarow; +use crate::google::sheet::{ CleanupSheet, Rows, Sheet, SheetId, SheetType, TabColorRGB, UpdateSheet, VirtualSheet, }; -use crate::spreadsheet::spreadsheet::GOOGLE_SPREADSHEET_MAXIMUM_CELLS; -use crate::spreadsheet::{Metadata, SpreadsheetAPI}; -use crate::{get_service_tab_color, jitter_duration, Sender, HOST_ID_CHARS_LIMIT}; +use crate::google::spreadsheet::GOOGLE_SPREADSHEET_MAXIMUM_CELLS; +use crate::google::{Metadata, SpreadsheetAPI}; +use crate::notifications::Sender; +use crate::rules::{rules_dropdowns, Rule, RULES_LOG_NAME}; +use crate::{get_service_tab_color, jitter_duration, HOST_ID_CHARS_LIMIT}; use chrono::{DateTime, Utc}; use std::collections::HashMap; use std::fmt; @@ -588,12 +589,12 @@ fn prepare_sheet_title( #[cfg(test)] mod tests { use super::*; + use crate::google::datavalue::{Datarow, Datavalue}; + use crate::google::sheet::tests::mock_ordinary_google_sheet; + use crate::google::spreadsheet::tests::TestState; + use crate::notifications::{Notification, Sender}; use crate::services::general::GENERAL_SERVICE_NAME; - use crate::spreadsheet::datavalue::{Datarow, Datavalue}; - use crate::spreadsheet::sheet::tests::mock_ordinary_google_sheet; - use crate::spreadsheet::spreadsheet::tests::TestState; use crate::tests::TEST_HOST_ID; - use crate::{Notification, Sender}; use chrono::NaiveDate; use google_sheets4::Error; use tokio::sync::mpsc;