From eaca4769a0d6c6e8c37e452332f950a6a649246d Mon Sep 17 00:00:00 2001 From: Denis-Cosmin NUTIU Date: Thu, 26 Dec 2024 12:58:38 +0200 Subject: [PATCH] extract redis into the infrastructure crate --- .idea/bluesky-bot.iml | 1 + Cargo.toml | 1 + infrastructure/Cargo.toml | 20 +++++++++++++++++++ infrastructure/readme.md | 7 +++++++ infrastructure/src/lib.rs | 3 +++ .../src/redis.rs | 0 scrapper/Cargo.toml | 9 +-------- scrapper/src/main.rs | 3 +-- 8 files changed, 34 insertions(+), 10 deletions(-) create mode 100644 infrastructure/Cargo.toml create mode 100644 infrastructure/readme.md create mode 100644 infrastructure/src/lib.rs rename scrapper/src/redis_service.rs => infrastructure/src/redis.rs (100%) diff --git a/.idea/bluesky-bot.iml b/.idea/bluesky-bot.iml index e7ffe8a..b4d9f0b 100644 --- a/.idea/bluesky-bot.iml +++ b/.idea/bluesky-bot.iml @@ -5,6 +5,7 @@ + diff --git a/Cargo.toml b/Cargo.toml index 379b2d3..80622dd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,7 @@ [workspace] members = [ "post", + "infrastructure", "scrapper", ] resolver = "2" diff --git a/infrastructure/Cargo.toml b/infrastructure/Cargo.toml new file mode 100644 index 0000000..e666094 --- /dev/null +++ b/infrastructure/Cargo.toml @@ -0,0 +1,20 @@ +[package] +name = "infrastructure" +version = "0.1.0" +edition = "2021" + +[dependencies] +tokio = { version = "1", features = ["full"] } +# Note: This appears unused by the RustRover analyzer, but it works. +# If in the future it stops working for whatever reason because the dependency has +# the same name as the module, then we can try to rename it using `package`. +redis = { version = "0.27.6", features = ["tokio-comp"] } +md5 = "0.7.0" +serde = { version = "1.0.216", features = ["derive"] } +serde_json = "1.0.134" +log = "0.4.22" + +[dev-dependencies] +rand = "0.8.5" +serial_test = "3.2.0" +post = {path = "../post"} \ No newline at end of file diff --git a/infrastructure/readme.md b/infrastructure/readme.md new file mode 100644 index 0000000..f466714 --- /dev/null +++ b/infrastructure/readme.md @@ -0,0 +1,7 @@ +# Infrastructure + +Implements shared infrastructure components. + +## RedisService + +A service for interacting with Redis. \ No newline at end of file diff --git a/infrastructure/src/lib.rs b/infrastructure/src/lib.rs new file mode 100644 index 0000000..a340eb5 --- /dev/null +++ b/infrastructure/src/lib.rs @@ -0,0 +1,3 @@ +pub mod redis; + +pub use redis::RedisService; diff --git a/scrapper/src/redis_service.rs b/infrastructure/src/redis.rs similarity index 100% rename from scrapper/src/redis_service.rs rename to infrastructure/src/redis.rs diff --git a/scrapper/Cargo.toml b/scrapper/Cargo.toml index ccb8cca..3bfe165 100644 --- a/scrapper/Cargo.toml +++ b/scrapper/Cargo.toml @@ -13,12 +13,5 @@ clokwerk = "0.4.0" log = "0.4.22" ctrlc = "3.4.5" clap = { version = "4.5.23", features = ["derive"] } -redis = { version = "0.27.6", features = ["tokio-comp"] } -md5 = "0.7.0" -serde = { version = "1.0.216", features = ["derive"] } -serde_json = "1.0.134" post = {path = "../post"} - -[dev-dependencies] -rand = "0.8.5" -serial_test = "3.2.0" \ No newline at end of file +infrastructure = { path = "../infrastructure"} \ No newline at end of file diff --git a/scrapper/src/main.rs b/scrapper/src/main.rs index 11adad2..db1ce75 100644 --- a/scrapper/src/main.rs +++ b/scrapper/src/main.rs @@ -1,9 +1,9 @@ use crate::cli::CliArgs; -use crate::redis_service::RedisService; use crate::scrapper::gfourmedia::G4Media; use crate::scrapper::WebScrapperEngine; use clap::Parser; use clokwerk::{AsyncScheduler, Interval, TimeUnits}; +use infrastructure::RedisService; use log::{debug, error, info}; use post::NewsPost; use std::sync::atomic::{AtomicBool, Ordering}; @@ -13,7 +13,6 @@ use std::time::Duration; use tokio::task::JoinHandle; mod cli; -mod redis_service; mod scrapper; /// Runs the scheduler in a separated thread.