sweeper module

main
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; mod nyazoom_headers;
pub mod ssr; pub mod ssr;
mod state; mod state;
mod sweeper;
mod util; mod util;
mod views; mod views;
@ -64,25 +65,7 @@ async fn main() -> io::Result<()> {
let state = cache::fetch_cache().await; let state = cache::fetch_cache().await;
// Spawn a repeating task that will clean files periodically let _ = sweeper::spawn_sweeper();
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();
}
}
}
}
});
// Router Setup // Router Setup
let app = Router::new() 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();
}
}
}
}
})
}