From 07b08447cdaed9890a3eb4a26cb6f946653a28c5 Mon Sep 17 00:00:00 2001 From: Josh Comer Date: Tue, 24 Oct 2023 09:58:37 -0300 Subject: [PATCH] Add db cleanup --- src/app/config.rs | 4 ++++ src/app/server.rs | 10 +++++++++- src/main.rs | 2 ++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/app/config.rs b/src/app/config.rs index 5670ada..ba5fb27 100644 --- a/src/app/config.rs +++ b/src/app/config.rs @@ -109,6 +109,10 @@ pub enum AppCommand { #[structopt(long = "db", value_name = "PATH", default_value = "hogan.db")] db_path: String, + ///Maximum age of db entries based on number of days + #[structopt(long = "db-max-age", value_name = "DAYS", default_value = "90")] + db_max_age: usize, + ///The delay between background fetches against the git repo #[structopt( long = "fetch-poller", diff --git a/src/app/server.rs b/src/app/server.rs index 545ae34..dabe1b0 100644 --- a/src/app/server.rs +++ b/src/app/server.rs @@ -2,7 +2,7 @@ use crate::app::config::AppCommon; use crate::app::datadogstatsd::{CustomMetrics, DdMetrics}; use crate::app::fetch_actor; use crate::app::head_actor; -use crate::storage::cache::Cache; +use crate::storage::cache::{Cache, CleanupActor}; use crate::storage::{lru, multi, sqlite}; use actix_web::dev::Service; use actix_web::middleware::Logger; @@ -92,6 +92,7 @@ pub fn start_up_server( datadog: bool, environment_pattern: String, db_path: String, + db_max_age: usize, fetch_poller: u64, allow_fetch: bool, ) -> Result<()> { @@ -121,6 +122,13 @@ pub fn start_up_server( Box::new(sqlite::SqliteCache::new(&db_path)), ])); + CleanupActor::init_db_cleanup_system( + &actor_system, + &[Arc::new(Box::new(sqlite::SqliteCache::new(&db_path)))], + db_max_age, + dd_metrics.clone(), + ); + let write_lock = Mutex::new(0); info!("Starting server on {}:{}", address, port); diff --git a/src/main.rs b/src/main.rs index 5f7ef5e..966f543 100644 --- a/src/main.rs +++ b/src/main.rs @@ -47,6 +47,7 @@ fn main() -> Result<()> { datadog, environment_pattern, db_path, + db_max_age, fetch_poller, allow_fetch, } => { @@ -59,6 +60,7 @@ fn main() -> Result<()> { datadog, environment_pattern, db_path, + db_max_age, fetch_poller, allow_fetch, )?;