refactor: cargo fmt across 27 files + behavioral fixes
Behavioral changes: - postgres_db: reorder default processors (cut first), prevent overwriting completed status - qdrant_db: fix scroll pagination exit condition (next.is_none()) - job_worker: add idempotency guards for face trace / TKG build; better error logging - main.rs: add LineWriter for stdout buffering Remaining diff is cargo fmt reformatting (line wrapping, import ordering).
This commit is contained in:
+99
-50
@@ -18,9 +18,9 @@ use serde::{Deserialize, Serialize};
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct PipelineStage {
|
||||
pub name: String,
|
||||
pub weight: f64, // Weight in overall progress (0.0-1.0)
|
||||
pub progress: f64, // Stage progress (0.0-1.0)
|
||||
pub status: String, // "pending", "running", "completed", "failed"
|
||||
pub weight: f64, // Weight in overall progress (0.0-1.0)
|
||||
pub progress: f64, // Stage progress (0.0-1.0)
|
||||
pub status: String, // "pending", "running", "completed", "failed"
|
||||
pub detail: Option<String>,
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ pub struct PipelineStage {
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct PipelineProgress {
|
||||
pub file_uuid: String,
|
||||
pub overall_progress: f64, // 0.0-1.0 weighted sum of all stages
|
||||
pub overall_progress: f64, // 0.0-1.0 weighted sum of all stages
|
||||
pub stages: Vec<PipelineStage>,
|
||||
pub updated_at: String,
|
||||
}
|
||||
@@ -40,23 +40,71 @@ impl PipelineProgress {
|
||||
overall_progress: 0.0,
|
||||
stages: vec![
|
||||
// Processors (30% total)
|
||||
PipelineStage { name: "processors".into(), weight: 0.30, progress: 0.0, status: "pending".into(), detail: None },
|
||||
PipelineStage {
|
||||
name: "processors".into(),
|
||||
weight: 0.30,
|
||||
progress: 0.0,
|
||||
status: "pending".into(),
|
||||
detail: None,
|
||||
},
|
||||
// Post-processor triggers (20% total)
|
||||
PipelineStage { name: "rule1_ingestion".into(), weight: 0.05, progress: 0.0, status: "pending".into(), detail: None },
|
||||
PipelineStage { name: "face_tracing".into(), weight: 0.05, progress: 0.0, status: "pending".into(), detail: None },
|
||||
PipelineStage { name: "identity_agent".into(), weight: 0.10, progress: 0.0, status: "pending".into(), detail: None },
|
||||
PipelineStage {
|
||||
name: "rule1_ingestion".into(),
|
||||
weight: 0.05,
|
||||
progress: 0.0,
|
||||
status: "pending".into(),
|
||||
detail: None,
|
||||
},
|
||||
PipelineStage {
|
||||
name: "face_tracing".into(),
|
||||
weight: 0.05,
|
||||
progress: 0.0,
|
||||
status: "pending".into(),
|
||||
detail: None,
|
||||
},
|
||||
PipelineStage {
|
||||
name: "identity_agent".into(),
|
||||
weight: 0.10,
|
||||
progress: 0.0,
|
||||
status: "pending".into(),
|
||||
detail: None,
|
||||
},
|
||||
// TKG Build (35% total)
|
||||
PipelineStage { name: "tkg_nodes".into(), weight: 0.20, progress: 0.0, status: "pending".into(), detail: None },
|
||||
PipelineStage { name: "tkg_edges".into(), weight: 0.15, progress: 0.0, status: "pending".into(), detail: None },
|
||||
PipelineStage {
|
||||
name: "tkg_nodes".into(),
|
||||
weight: 0.20,
|
||||
progress: 0.0,
|
||||
status: "pending".into(),
|
||||
detail: None,
|
||||
},
|
||||
PipelineStage {
|
||||
name: "tkg_edges".into(),
|
||||
weight: 0.15,
|
||||
progress: 0.0,
|
||||
status: "pending".into(),
|
||||
detail: None,
|
||||
},
|
||||
// Rule 2 Ingestion (15%)
|
||||
PipelineStage { name: "rule2_ingestion".into(), weight: 0.15, progress: 0.0, status: "pending".into(), detail: None },
|
||||
PipelineStage {
|
||||
name: "rule2_ingestion".into(),
|
||||
weight: 0.15,
|
||||
progress: 0.0,
|
||||
status: "pending".into(),
|
||||
detail: None,
|
||||
},
|
||||
],
|
||||
updated_at: chrono::Utc::now().to_rfc3339(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Update a stage's progress and recalculate overall progress
|
||||
pub fn update_stage(&mut self, stage_name: &str, progress: f64, status: &str, detail: Option<String>) {
|
||||
pub fn update_stage(
|
||||
&mut self,
|
||||
stage_name: &str,
|
||||
progress: f64,
|
||||
status: &str,
|
||||
detail: Option<String>,
|
||||
) {
|
||||
if let Some(stage) = self.stages.iter_mut().find(|s| s.name == stage_name) {
|
||||
stage.progress = progress.clamp(0.0, 1.0);
|
||||
stage.status = status.to_string();
|
||||
@@ -67,7 +115,9 @@ impl PipelineProgress {
|
||||
|
||||
/// Recalculate overall progress as weighted sum
|
||||
fn recalculate_overall(&mut self) {
|
||||
self.overall_progress = self.stages.iter()
|
||||
self.overall_progress = self
|
||||
.stages
|
||||
.iter()
|
||||
.map(|s| s.weight * s.progress)
|
||||
.sum::<f64>()
|
||||
.clamp(0.0, 1.0);
|
||||
@@ -90,24 +140,24 @@ impl PipelineProgress {
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum TkgPhase {
|
||||
FaceTracing = 0, // Phase 0: Populate trace_id from face.json
|
||||
FaceTrackNodes = 1, // Build face_track nodes
|
||||
GazeTrackNodes = 2, // Build gaze_track nodes
|
||||
LipTrackNodes = 3, // Build lip_track nodes
|
||||
TextRegionNodes = 4, // Build text_region nodes
|
||||
AppearanceNodes = 5, // Build appearance_trace nodes
|
||||
AccessoryNodes = 6, // Build accessory nodes
|
||||
ObjectNodes = 7, // Build yolo_object nodes
|
||||
HandNodes = 8, // Build hand nodes
|
||||
SpeakerNodes = 9, // Build speaker nodes
|
||||
CoOccurrenceEdges = 10, // Build co_occurrence edges
|
||||
SpeakerFaceEdges = 11, // Build speaker_face edges
|
||||
FaceFaceEdges = 12, // Build face_face edges
|
||||
MutualGazeEdges = 13, // Build mutual_gaze edges
|
||||
LipSyncEdges = 14, // Build lip_sync edges
|
||||
HasAppearanceEdges = 15,// Build has_appearance edges
|
||||
WearsEdges = 16, // Build wears edges
|
||||
HandObjectEdges = 17, // Build hand_object edges
|
||||
FaceTracing = 0, // Phase 0: Populate trace_id from face.json
|
||||
FaceTrackNodes = 1, // Build face_track nodes
|
||||
GazeTrackNodes = 2, // Build gaze_track nodes
|
||||
LipTrackNodes = 3, // Build lip_track nodes
|
||||
TextRegionNodes = 4, // Build text_region nodes
|
||||
AppearanceNodes = 5, // Build appearance_trace nodes
|
||||
AccessoryNodes = 6, // Build accessory nodes
|
||||
ObjectNodes = 7, // Build yolo_object nodes
|
||||
HandNodes = 8, // Build hand nodes
|
||||
SpeakerNodes = 9, // Build speaker nodes
|
||||
CoOccurrenceEdges = 10, // Build co_occurrence edges
|
||||
SpeakerFaceEdges = 11, // Build speaker_face edges
|
||||
FaceFaceEdges = 12, // Build face_face edges
|
||||
MutualGazeEdges = 13, // Build mutual_gaze edges
|
||||
LipSyncEdges = 14, // Build lip_sync edges
|
||||
HasAppearanceEdges = 15, // Build has_appearance edges
|
||||
WearsEdges = 16, // Build wears edges
|
||||
HandObjectEdges = 17, // Build hand_object edges
|
||||
Completed = 18,
|
||||
Failed = 19,
|
||||
}
|
||||
@@ -282,12 +332,7 @@ impl TkgProgress {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update_phase(
|
||||
&mut self,
|
||||
phase: TkgPhase,
|
||||
phase_progress: f64,
|
||||
message: &str,
|
||||
) {
|
||||
pub fn update_phase(&mut self, phase: TkgPhase, phase_progress: f64, message: &str) {
|
||||
self.phase = phase.name().to_string();
|
||||
self.phase_index = phase as usize;
|
||||
self.phase_progress = phase_progress.clamp(0.0, 1.0);
|
||||
@@ -339,12 +384,7 @@ impl AgentProgress {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update_phase(
|
||||
&mut self,
|
||||
phase: AgentPhase,
|
||||
phase_progress: f64,
|
||||
message: &str,
|
||||
) {
|
||||
pub fn update_phase(&mut self, phase: AgentPhase, phase_progress: f64, message: &str) {
|
||||
self.phase = phase.name().to_string();
|
||||
self.phase_index = phase as usize;
|
||||
self.phase_progress = phase_progress.clamp(0.0, 1.0);
|
||||
@@ -357,13 +397,21 @@ impl AgentProgress {
|
||||
}
|
||||
|
||||
pub fn mark_completed(&mut self) {
|
||||
self.update_phase(AgentPhase::Completed, 1.0, "Identity Agent processing completed");
|
||||
self.update_phase(
|
||||
AgentPhase::Completed,
|
||||
1.0,
|
||||
"Identity Agent processing completed",
|
||||
);
|
||||
self.overall_progress = 1.0;
|
||||
self.phase_progress = 1.0;
|
||||
}
|
||||
|
||||
pub fn mark_failed(&mut self, error: &str) {
|
||||
self.update_phase(AgentPhase::Failed, 0.0, &format!("Identity Agent failed: {}", error));
|
||||
self.update_phase(
|
||||
AgentPhase::Failed,
|
||||
0.0,
|
||||
&format!("Identity Agent failed: {}", error),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -482,10 +530,7 @@ pub async fn publish_agent_progress(
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn get_progress(
|
||||
redis: &Arc<RedisClient>,
|
||||
file_uuid: &str,
|
||||
) -> Option<CombinedProgress> {
|
||||
pub async fn get_progress(redis: &Arc<RedisClient>, file_uuid: &str) -> Option<CombinedProgress> {
|
||||
let tkg_key = format!(
|
||||
"{}progress:{}:tkg",
|
||||
crate::core::config::REDIS_KEY_PREFIX.as_str(),
|
||||
@@ -542,7 +587,11 @@ pub async fn publish_pipeline_progress(
|
||||
// Merge: update stages from new progress onto existing
|
||||
for new_stage in &progress.stages {
|
||||
if new_stage.status == "completed" || new_stage.progress > 0.0 {
|
||||
if let Some(existing_stage) = existing.stages.iter_mut().find(|s| s.name == new_stage.name) {
|
||||
if let Some(existing_stage) = existing
|
||||
.stages
|
||||
.iter_mut()
|
||||
.find(|s| s.name == new_stage.name)
|
||||
{
|
||||
existing_stage.status = new_stage.status.clone();
|
||||
existing_stage.progress = new_stage.progress;
|
||||
existing_stage.detail = new_stage.detail.clone();
|
||||
|
||||
Reference in New Issue
Block a user