sweeper module

This commit is contained in:
Zynh Ludwig 2024-08-28 18:57:36 -07:00
parent 31bfd4d126
commit 7128b9e304
2 changed files with 25 additions and 19 deletions

View file

@ -32,6 +32,7 @@ mod cache;
mod nyazoom_headers;
pub mod ssr;
mod state;
mod sweeper;
mod util;
mod views;
@ -64,25 +65,7 @@ async fn main() -> io::Result<()> {
let state = cache::fetch_cache().await;
// Spawn a repeating task that will clean files periodically
tokio::spawn({
let state = state.clone();
async move {
loop {
tokio::time::sleep(Duration::from_secs(15 * 60)).await;
tracing::info!("Cleaning Sweep!");
let mut records = state.records.lock().await;
for (key, record) in records.clone().into_iter() {
if !record.can_be_downloaded() {
tracing::info!("culling: {:?}", record);
records.remove_record(&key).await.unwrap();
}
}
}
}
});
let _ = sweeper::spawn_sweeper();
// Router Setup
let app = Router::new()

23
src/sweeper.rs Normal file
View file

@ -0,0 +1,23 @@
use tokio::task::JoinHandle;
pub fn spawn_sweeper() -> JoinHandle<!> {
// Spawn a repeating task that will clean files periodically
tokio::spawn({
let state = state.clone();
async move {
loop {
tokio::time::sleep(Duration::from_secs(15 * 60)).await;
tracing::info!("Cleaning Sweep!");
let mut records = state.records.lock().await;
for (key, record) in records.clone().into_iter() {
if !record.can_be_downloaded() {
tracing::info!("culling: {:?}", record);
records.remove_record(&key).await.unwrap();
}
}
}
}
})
}