finish up janitor

This commit is contained in:
blek 2023-10-12 20:43:02 +10:00
parent 32d5666477
commit ea7d285b7a
Signed by: blek
GPG Key ID: 14546221E3595D0C
2 changed files with 14 additions and 1 deletions

View File

@ -13,6 +13,14 @@ async fn check_key(key: String, mut client: redis::Client) -> bool {
let val: String = client.get(key.clone()).unwrap(); let val: String = client.get(key.clone()).unwrap();
let file: File = serde_json::from_str(val.as_str()).unwrap(); let file: File = serde_json::from_str(val.as_str()).unwrap();
if file.expired() {
#[cfg(debug_assertions)] {
log::debug!("Object {key} is marked for deletion because it has expired");
}
client.del::<String, ()>(key).unwrap();
return true;
}
if ! Path::new(&file.path.clone()).exists() { if ! Path::new(&file.path.clone()).exists() {
#[cfg(debug_assertions)] { #[cfg(debug_assertions)] {
log::debug!("Object {key} is marked for deletion because it doesn't exist in the filesystem"); log::debug!("Object {key} is marked for deletion because it doesn't exist in the filesystem");
@ -23,6 +31,9 @@ async fn check_key(key: String, mut client: redis::Client) -> bool {
let stat = tokio::fs::metadata(file.clone().path).await.unwrap(); let stat = tokio::fs::metadata(file.clone().path).await.unwrap();
if ! stat.is_file() { if ! stat.is_file() {
#[cfg(debug_assertions)] {
log::debug!("Object {key} is marked for deletion because it exists in the filesystem, but is not a file");
}
client.del::<String, ()>(key).unwrap(); client.del::<String, ()>(key).unwrap();
return true; return true;
} }

View File

@ -36,13 +36,15 @@ async fn main() {
if res.is_err() { if res.is_err() {
log::error!("Error while cleaning: {}", res.unwrap_err()); log::error!("Error while cleaning: {}", res.unwrap_err());
log::error!("Retrying in {}", std::env::var("CLEAN_ERRDEL").unwrap()); log::error!("Retrying in {}", std::env::var("CLEAN_ERRDEL").unwrap());
log::debug!("Next clean will run at {}", chrono::Local::now() + env.clean_errdel);
tokio::time::sleep(envy.clean_errdel).await; tokio::time::sleep(envy.clean_errdel).await;
continue; continue;
} }
#[cfg(debug_assertions)] { #[cfg(debug_assertions)] {
log::debug!("Cleaned successfully"); log::debug!("Cleaned successfully");
log::debug!("Next clean is scheduled in {}", std::env::var("CLEAN_DEL").unwrap()) log::debug!("Next clean is scheduled in {}", std::env::var("CLEAN_DEL").unwrap());
log::debug!("Next clean will run at {}", chrono::Local::now() + env.clean_del);
} }
tokio::time::sleep(envy.clean_errdel).await; tokio::time::sleep(envy.clean_errdel).await;