Skip to content

Commit

Permalink
Add db cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jjcomer committed Oct 24, 2023
1 parent 48e0b32 commit 07b0844
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/app/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 9 additions & 1 deletion src/app/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<()> {
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ fn main() -> Result<()> {
datadog,
environment_pattern,
db_path,
db_max_age,
fetch_poller,
allow_fetch,
} => {
Expand All @@ -59,6 +60,7 @@ fn main() -> Result<()> {
datadog,
environment_pattern,
db_path,
db_max_age,
fetch_poller,
allow_fetch,
)?;
Expand Down

0 comments on commit 07b0844

Please sign in to comment.