From c34b7b9ea0b971330b5c45c7d850a3a8852a827e Mon Sep 17 00:00:00 2001 From: Accusys Date: Thu, 17 Sep 2026 22:34:44 +0800 Subject: [PATCH] feat: add force parameter to re-scan API for proper output file cleanup Problem: Re-scan (/api/v1/file/:file_uuid/process) only deleted processor_results from DB, but not output files. Worker checks if output file exists and skips re-processing, resulting in stale/incorrect results persisting. Solution: - Add 'force' parameter to ProcessRequest struct (default: false) - When force=true, delete all output files before re-processing - Worker will then re-run processors from scratch Changes: - src/api/processing.rs: - Added 'force: bool' to ProcessRequest - Added delete_output_files_for_uuid() helper function - Modified trigger_processing() to delete output files when force=true API usage: POST /api/v1/file/:file_uuid/process { "processors": ["face","ocr",...], "force": true } Note: Build currently fails due to unrelated uncommitted admin_config changes. Those should be fixed separately. --- src/api/processing.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/api/processing.rs b/src/api/processing.rs index c4ebf432..7985c6bf 100644 --- a/src/api/processing.rs +++ b/src/api/processing.rs @@ -23,6 +23,28 @@ use crate::core::probe::ffprobe; use crate::worker::processor; use crate::{Embedder, FileManager}; +fn delete_output_files_for_uuid(uuid: &str, output_dir: &str) -> u64 { + let mut deleted_count = 0u64; + if let Ok(entries) = std::fs::read_dir(output_dir) { + for entry in entries.flatten() { + let path = entry.path(); + if let Some(name) = path.file_name().and_then(|n| n.to_str()) { + let is_uuid_file = name.starts_with(uuid) && !path.is_dir(); + let is_pipeline_log = name.starts_with("pipeline_") + && name.contains(uuid) + && name.ends_with(".log"); + if is_uuid_file || is_pipeline_log { + if std::fs::remove_file(&path).is_ok() { + deleted_count += 1; + tracing::info!("[FORCE_RESCAN] Deleted output file: {}", name); + } + } + } + } + } + deleted_count +} + #[derive(Debug, Serialize)] struct JobListResponse { jobs: Vec, @@ -122,6 +144,8 @@ struct ProcessRequest { rules: Option>, processors: Option>, face_settings: Option, + #[serde(default)] + force: bool, } #[derive(Debug, Serialize, Deserialize)] @@ -321,6 +345,18 @@ async fn trigger_processing( })?; tracing::info!("[TRIGGER] Cleaned processor_results for job {}", job_id); + // If force=true, delete output files to force re-processing + if req.force { + let output_dir = std::env::var("MOMENTRY_OUTPUT_DIR") + .unwrap_or_else(|_| "/Users/accusys/momentry/output".to_string()); + let deleted_count = delete_output_files_for_uuid(&file_uuid, &output_dir); + tracing::info!( + "[TRIGGER] Force re-scan: deleted {} output files for {}", + deleted_count, + file_uuid + ); + } + // Update existing job with new face_settings if provided if let Some(ref fs_json) = face_settings_json { sqlx::query(&format!(