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.
This commit is contained in:
@@ -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<JobInfoResponse>,
|
||||
@@ -122,6 +144,8 @@ struct ProcessRequest {
|
||||
rules: Option<Vec<String>>,
|
||||
processors: Option<Vec<String>>,
|
||||
face_settings: Option<FaceSettings>,
|
||||
#[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!(
|
||||
|
||||
Reference in New Issue
Block a user