Compare commits
No commits in common. "772bda8e934d094dfe0bd06c19ead65b4c41c9b4" and "7128b9e3046653a6175c234a70fe7887476dc084" have entirely different histories.
772bda8e93
...
7128b9e304
|
@ -17,7 +17,7 @@ use nyazoom_headers::ForwardedFor;
|
||||||
|
|
||||||
use sanitize_filename_reader_friendly::sanitize;
|
use sanitize_filename_reader_friendly::sanitize;
|
||||||
|
|
||||||
use std::{io, net::SocketAddr, path::Path};
|
use std::{io, net::SocketAddr, path::Path, time::Duration};
|
||||||
|
|
||||||
use tokio_util::{
|
use tokio_util::{
|
||||||
compat::FuturesAsyncWriteCompatExt,
|
compat::FuturesAsyncWriteCompatExt,
|
||||||
|
@ -65,7 +65,7 @@ async fn main() -> io::Result<()> {
|
||||||
|
|
||||||
let state = cache::fetch_cache().await;
|
let state = cache::fetch_cache().await;
|
||||||
|
|
||||||
sweeper::spawn_sweeper(state.clone());
|
let _ = sweeper::spawn_sweeper();
|
||||||
|
|
||||||
// Router Setup
|
// Router Setup
|
||||||
let app = Router::new()
|
let app = Router::new()
|
||||||
|
@ -87,6 +87,7 @@ async fn main() -> io::Result<()> {
|
||||||
|
|
||||||
// Server creation
|
// Server creation
|
||||||
let addr = SocketAddr::from(([0, 0, 0, 0], 3000));
|
let addr = SocketAddr::from(([0, 0, 0, 0], 3000));
|
||||||
|
tracing::debug!("listening on http://{}/", addr);
|
||||||
let listener = tokio::net::TcpListener::bind(&addr).await.unwrap();
|
let listener = tokio::net::TcpListener::bind(&addr).await.unwrap();
|
||||||
axum::serve(
|
axum::serve(
|
||||||
listener,
|
listener,
|
||||||
|
@ -95,8 +96,6 @@ async fn main() -> io::Result<()> {
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
tracing::debug!("listening on http://{}/", addr);
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,22 +1,23 @@
|
||||||
use std::time::Duration;
|
use tokio::task::JoinHandle;
|
||||||
|
|
||||||
use crate::state::{AppState, AsyncRemoveRecord};
|
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!");
|
||||||
|
|
||||||
/// Spawn a repeating task that will clean files periodically
|
let mut records = state.records.lock().await;
|
||||||
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() {
|
||||||
for (key, record) in records.clone().into_iter() {
|
tracing::info!("culling: {:?}", record);
|
||||||
if !record.can_be_downloaded() {
|
records.remove_record(&key).await.unwrap();
|
||||||
tracing::info!("culling: {:?}", record);
|
}
|
||||||
records.remove_record(&key).await.unwrap();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue