diff --git a/config/pipeline_flows.json b/config/pipeline_flows.json index 1214da60..bc9095cb 100644 --- a/config/pipeline_flows.json +++ b/config/pipeline_flows.json @@ -39,7 +39,7 @@ "icon": "analysis", "parallel_strategy": "limited_parallel", "max_concurrent": 3, - "processors": ["scene", "face_trace", "face_cluster"] + "processors": ["scene_vlm", "face_trace", "face_cluster"] }, { "id": 4, @@ -189,8 +189,8 @@ "on_failure": "continue" }, { - "name": "scene", - "processor_type": "scene", + "name": "scene_vlm", + "processor_type": "scene_vlm", "phase": 3, "phase_name": "深度分析", "phase_name_en": "Deep Analysis", diff --git a/src/core/db/postgres_db.rs b/src/core/db/postgres_db.rs index cf7bf358..753dfd3d 100644 --- a/src/core/db/postgres_db.rs +++ b/src/core/db/postgres_db.rs @@ -2327,16 +2327,24 @@ impl PostgresDb { .to_string() }); + // Get enabled processors from pipeline config + let cfg = crate::core::pipeline_config::get(); + let processors = cfg.get_enabled_processors("register"); + let processors_array = format!("ARRAY[{}]", processors.iter() + .map(|p| format!("'{}'", p)) + .collect::>() + .join(",")); + let row = if let Some(job_id) = existing_id { // Update existing job sqlx::query( &format!( r#" - UPDATE {} SET status = 'pending', video_path = $1, video_id = $2, face_settings = $3::jsonb, updated_at = NOW() + UPDATE {} SET status = 'pending', video_path = $1, video_id = $2, face_settings = $3::jsonb, processors = {}::text[], updated_at = NOW() WHERE id = $4 RETURNING id, uuid, video_path, status, current_processor, progress_total, progress_current, error_count, last_error, started_at::TEXT, updated_at::TEXT, created_at::TEXT, processors, completed_processors, failed_processors, video_id, face_settings::text "#, - jobs_table + jobs_table, processors_array ) ) .bind(video_path) @@ -2351,10 +2359,10 @@ impl PostgresDb { &format!( r#" INSERT INTO {} (uuid, video_path, status, video_id, processors, face_settings) - VALUES ($1, $2, 'pending', $3, ARRAY['cut','asr','face','face_cluster','ocr','asrx'], $4::jsonb) + VALUES ($1, $2, 'pending', $3, {}::text[], $4::jsonb) RETURNING id, uuid, video_path, status, current_processor, progress_total, progress_current, error_count, last_error, started_at::TEXT, updated_at::TEXT, created_at::TEXT, processors, completed_processors, failed_processors, video_id, face_settings::text "#, - jobs_table + jobs_table, processors_array ) ) .bind(uuid) diff --git a/src/core/pipeline_config.rs b/src/core/pipeline_config.rs index b67878ba..b48127ef 100644 --- a/src/core/pipeline_config.rs +++ b/src/core/pipeline_config.rs @@ -149,6 +149,30 @@ impl PipelineFlows { .filter(|&t| t > 0) .unwrap_or(self.default_timeout_secs) } + + /// Get all enabled processor names for a specific flow. + /// Handles stage-to-processor mapping (e.g., asr_asrx → asr + asrx). + pub fn get_enabled_processors(&self, flow_name: &str) -> Vec { + let empty_vec = Vec::new(); + let stages = self + .flows + .get(flow_name) + .map(|f| &f.stages) + .unwrap_or(&empty_vec); + + let mut processors = Vec::new(); + for stage in stages.iter().filter(|s| s.enabled) { + // Map stage names to processor names + let mapped = match stage.name.as_str() { + "asr_asrx" => vec!["asr".to_string(), "asrx".to_string()], + "scene_vlm" => vec!["scene_vlm".to_string()], + "tkg" => vec!["tkg".to_string()], + other => vec![other.to_string()], + }; + processors.extend(mapped); + } + processors + } } #[cfg(test)] @@ -164,15 +188,34 @@ mod tests { #[test] fn test_scene_declared_parallel() { - // The shipped config declares the scene stage as parallel. + // The shipped config declares the scene_vlm stage as parallel. let cfg = get(); assert!( - cfg.is_parallel("register", "scene"), - "scene stage must be parallel in pipeline_flows.json" + cfg.is_parallel("register", "scene_vlm"), + "scene_vlm stage must be parallel in pipeline_flows.json" ); assert_eq!( - cfg.dependencies("register", "scene"), + cfg.dependencies("register", "scene_vlm"), vec!["cut".to_string()] ); } + + #[test] + fn test_get_enabled_processors() { + let cfg = get(); + let processors = cfg.get_enabled_processors("register"); + + // Should include all enabled processors + assert!(processors.contains(&"cut".to_string())); + assert!(processors.contains(&"asr".to_string())); + assert!(processors.contains(&"asrx".to_string())); + assert!(processors.contains(&"face".to_string())); + assert!(processors.contains(&"ocr".to_string())); + assert!(processors.contains(&"scene_vlm".to_string())); + assert!(processors.contains(&"face_trace".to_string())); + assert!(processors.contains(&"face_cluster".to_string())); + + // asr_asrx should be split into asr + asrx + assert!(!processors.contains(&"asr_asrx".to_string())); + } } diff --git a/src/worker/job_worker.rs b/src/worker/job_worker.rs index b657aa86..10e6dc92 100644 --- a/src/worker/job_worker.rs +++ b/src/worker/job_worker.rs @@ -714,7 +714,8 @@ impl JobWorker { "[COMMAND_QUEUE] Auto-pipeline job {} created for {}", job.id, file_uuid ); - let all_procs: Vec<&str> = vec!["cut", "asr", "asrx", "ocr", "face"]; + let cfg = crate::core::pipeline_config::get(); + let all_procs: Vec = cfg.get_enabled_processors("register"); let total: i64 = sqlx::query_scalar(&format!( "SELECT COALESCE(total_frames, 0) FROM {} WHERE file_uuid = $1", schema::table_name("videos") @@ -723,9 +724,10 @@ impl JobWorker { .fetch_one(self.db.pool()) .await .unwrap_or(0); + let proc_refs: Vec<&str> = all_procs.iter().map(|s| s.as_str()).collect(); let _ = self .db - .init_processing_status(&file_uuid, all_procs, total as u64) + .init_processing_status(&file_uuid, proc_refs, total as u64) .await; let _ = sqlx::query(&format!( "UPDATE {} SET status = 'scanning' WHERE file_uuid = $1",