actually cull files?

main
Zynh0722 2023-07-27 08:58:13 -07:00
parent b93a3950d0
commit e6c996d7d8
1 changed files with 23 additions and 8 deletions

View File

@ -57,19 +57,34 @@ async fn main() -> io::Result<()> {
.with(tracing_subscriber::fmt::layer()) .with(tracing_subscriber::fmt::layer())
.init(); .init();
// Spawn a repeating task that will clean files periodically
tokio::spawn(async {
loop {
tracing::info!("Cleaning Sweep!");
tokio::time::sleep(Duration::from_secs(15 * 60)).await
}
});
// uses create_dir_all to create both .cache and serve inside it in one go // uses create_dir_all to create both .cache and serve inside it in one go
util::make_dir(".cache/serve").await?; util::make_dir(".cache/serve").await?;
let state = cache::fetch_cache().await; let state = cache::fetch_cache().await;
// Spawn a repeating task that will clean files periodically
tokio::spawn({
let state = state.clone();
async move {
loop {
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!("{:?} should be culled", record);
let _ = tokio::fs::remove_file(&record.file).await;
records.remove(key.as_str());
cache::write_to_cache(&records).await.unwrap();
}
}
tokio::time::sleep(Duration::from_secs(15 * 60)).await
}
}
});
// Router Setup // Router Setup
let app = Router::new() let app = Router::new()
.route("/", get(welcome)) .route("/", get(welcome))