fixed sweeper module
This commit is contained in:
parent
7128b9e304
commit
7444fc4f9b
2 changed files with 17 additions and 18 deletions
|
@ -17,7 +17,7 @@ use nyazoom_headers::ForwardedFor;
|
|||
|
||||
use sanitize_filename_reader_friendly::sanitize;
|
||||
|
||||
use std::{io, net::SocketAddr, path::Path, time::Duration};
|
||||
use std::{io, net::SocketAddr, path::Path};
|
||||
|
||||
use tokio_util::{
|
||||
compat::FuturesAsyncWriteCompatExt,
|
||||
|
@ -65,7 +65,7 @@ async fn main() -> io::Result<()> {
|
|||
|
||||
let state = cache::fetch_cache().await;
|
||||
|
||||
let _ = sweeper::spawn_sweeper();
|
||||
sweeper::spawn_sweeper(state.clone());
|
||||
|
||||
// Router Setup
|
||||
let app = Router::new()
|
||||
|
|
|
@ -1,23 +1,22 @@
|
|||
use tokio::task::JoinHandle;
|
||||
use std::time::Duration;
|
||||
|
||||
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!");
|
||||
use crate::state::{AppState, AsyncRemoveRecord};
|
||||
|
||||
let mut records = state.records.lock().await;
|
||||
/// 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!");
|
||||
|
||||
for (key, record) in records.clone().into_iter() {
|
||||
if !record.can_be_downloaded() {
|
||||
tracing::info!("culling: {:?}", record);
|
||||
records.remove_record(&key).await.unwrap();
|
||||
}
|
||||
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