2 Commits

Author SHA1 Message Date
2676515b4e Merge pull request 'Use spawn_blocking for ingest scan' (#286) from 283-web-server-stops-responding-during-ingest into main
All checks were successful
Push Workflows / leptos-test (push) Successful in 2m43s
Push Workflows / docs (push) Successful in 2m16s
Push Workflows / rustfmt (push) Successful in 10s
Push Workflows / clippy (push) Successful in 1m26s
Push Workflows / mdbook (push) Successful in 15s
Push Workflows / test (push) Successful in 3m16s
Push Workflows / mdbook-server (push) Successful in 35s
Push Workflows / build (push) Successful in 6m24s
Push Workflows / nix-build (push) Successful in 9m19s
Push Workflows / docker-build (push) Successful in 11m33s
Reviewed-on: #286
2025-12-01 22:36:55 +00:00
c498e1a7fa Use spawn_blocking for ingest scan
All checks were successful
Push Workflows / rustfmt (push) Successful in 8s
Push Workflows / mdbook (push) Successful in 18s
Push Workflows / clippy (push) Successful in 1m3s
Push Workflows / docs (push) Successful in 1m33s
Push Workflows / mdbook-server (push) Successful in 1m23s
Push Workflows / leptos-test (push) Successful in 2m0s
Push Workflows / test (push) Successful in 2m8s
Push Workflows / build (push) Successful in 3m14s
Push Workflows / docker-build (push) Successful in 4m11s
Push Workflows / nix-build (push) Successful in 6m16s
2025-12-01 17:30:01 -05:00
2 changed files with 13 additions and 4 deletions

View File

@@ -5,7 +5,7 @@ use crate::prelude::*;
use image_convert::ImageResource;
use std::path::{Path, PathBuf};
pub async fn full_scan(state: &BackendState) {
pub fn full_scan(state: &BackendState) {
info!("Ingest running...");
let ingest_path = state.config.audio_path.clone();

View File

@@ -1,7 +1,7 @@
use crate::ingest::scan::full_scan;
use crate::prelude::*;
use tokio::task::{JoinHandle, spawn};
use tokio::task::{JoinHandle, spawn, spawn_blocking};
use tokio::time::{Duration, Instant, interval_at};
pub const INITIAL_SCAN_DELAY: Duration = Duration::from_secs(10);
@@ -10,7 +10,7 @@ pub const SCAN_INTERVAL: Duration = Duration::from_hours(1);
/// Start the ingest task
/// Waits an initial delay for startup to complete, then runs a full ingest
/// scan on a regular interval
pub async fn start_task(state: BackendState) -> JoinHandle<!> {
pub fn start_task(state: BackendState) -> JoinHandle<!> {
info!("Starting ingest task...");
let start_time = Instant::now() + INITIAL_SCAN_DELAY;
@@ -19,7 +19,16 @@ pub async fn start_task(state: BackendState) -> JoinHandle<!> {
spawn(async move {
loop {
scan_interval.tick().await;
full_scan(&state).await;
let state = state.clone();
let scan_handle = spawn_blocking(move || {
full_scan(&state);
});
if let Err(e) = scan_handle.await {
error!("Ingest scan panicked: {e}");
}
}
})
}