sweeper module
This commit is contained in:
parent
31bfd4d126
commit
7128b9e304
2 changed files with 25 additions and 19 deletions
21
src/main.rs
21
src/main.rs
|
@ -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
23
src/sweeper.rs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
Loading…
Reference in a new issue