From 8ba35aae90cef1b0c4a973e1c419d8930033b2ab Mon Sep 17 00:00:00 2001 From: perf3ct Date: Sun, 15 Jun 2025 16:38:27 +0000 Subject: [PATCH] feat(async): create dedicated threads for ocr_runtime --- src/main.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index e9da6e0..4eadc93 100644 --- a/src/main.rs +++ b/src/main.rs @@ -143,14 +143,21 @@ async fn main() -> Result<(), Box> { } }); - // Create dedicated runtime for background tasks to prevent interference + // Create dedicated runtime for OCR processing to prevent interference with WebDAV + let ocr_runtime = tokio::runtime::Builder::new_multi_thread() + .worker_threads(3) // Dedicated threads for OCR work + .thread_name("readur-ocr") + .enable_all() + .build()?; + + // Create separate runtime for other background tasks (WebDAV, maintenance) let background_runtime = tokio::runtime::Builder::new_multi_thread() - .worker_threads(2) // Dedicated threads for background work + .worker_threads(2) // Dedicated threads for WebDAV and maintenance .thread_name("readur-background") .enable_all() .build()?; - // Start OCR queue worker on dedicated runtime + // Start OCR queue worker on dedicated OCR runtime let concurrent_jobs = 4; // TODO: Get from config/settings let queue_service = Arc::new(readur::ocr_queue::OcrQueueService::new( state.db.clone(), @@ -159,15 +166,15 @@ async fn main() -> Result<(), Box> { )); let queue_worker = queue_service.clone(); - background_runtime.spawn(async move { + ocr_runtime.spawn(async move { if let Err(e) = queue_worker.start_worker().await { error!("OCR queue worker error: {}", e); } }); - // Start maintenance tasks on background runtime + // Start OCR maintenance tasks on dedicated OCR runtime let queue_maintenance = queue_service.clone(); - background_runtime.spawn(async move { + ocr_runtime.spawn(async move { let mut interval = tokio::time::interval(std::time::Duration::from_secs(300)); // Every 5 minutes loop { interval.tick().await;