1
0
Fork 0
nyazoom/src/sweeper.rs

23 lines
687 B
Rust
Raw Normal View History

2024-08-29 02:02:30 +00:00
use std::time::Duration;
2024-08-29 01:57:36 +00:00
2024-08-29 02:02:30 +00:00
use crate::state::{AppState, AsyncRemoveRecord};
2024-08-29 01:57:36 +00:00
2024-08-29 02:02:30 +00:00
/// Spawn a repeating task that will clean files periodically
pub fn spawn_sweeper(state: AppState) {
tokio::spawn(async move {
loop {
tokio::time::sleep(Duration::from_secs(15 * 60)).await;
tracing::info!("Cleaning Sweep!");
2024-08-29 01:57:36 +00:00
2024-08-29 02:02:30 +00:00
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();
2024-08-29 01:57:36 +00:00
}
}
}
2024-08-29 02:02:30 +00:00
});
2024-08-29 01:57:36 +00:00
}