use std::time::Duration; use crate::state::{AppState, AsyncRemoveRecord}; /// 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!"); 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(); } } } }); }