882e31ab96
Consolidated snapshot (previously WIP in working tree). - core/pipeline_config: new module loading config/pipeline_flows.json as the source of truth for stage execution mode (parallel/blocking) and dependencies - worker/job_worker: dispatch Scene VLM to a background task when the stage is declared parallel, unblocking the worker poll loop; resolve processor dependencies from pipeline_flows.json (fallback to built-in) - config/pipeline_flows.json: asrx depends on [cut, asr] - scripts/fix_stuck_jobs: fix UTC timezone comparison, raise default threshold to 6h, skip jobs with recent processor activity - rust_asrx: Rust speaker diarization CLI + processor wiring - processor metadata helper; fast_face_clustering script; file_progress pipeline API; scan API; VAD updates
179 lines
5.5 KiB
Rust
179 lines
5.5 KiB
Rust
//! Declarative pipeline flow configuration (`config/pipeline_flows.json`).
|
|
//!
|
|
//! This module is the single source of truth for *how* the worker executes each
|
|
//! pipeline stage. In particular, the `parallel` flag on a stage declares whether
|
|
//! that stage runs in the background (non-blocking) or sequentially (the caller
|
|
//! waits for it to finish). The worker reads `parallel` from here instead of
|
|
//! hardcoding the execution mode per stage.
|
|
//!
|
|
//! Example: the `scene` stage (Scene VLM) is declared `"parallel": true`, so the
|
|
//! worker dispatches it to a background task rather than awaiting it inline in the
|
|
//! poll loop.
|
|
//!
|
|
//! Loaded once and cached. Edit `config/pipeline_flows.json` and restart the worker
|
|
//! to apply changes.
|
|
|
|
use std::collections::HashMap;
|
|
use std::sync::OnceLock;
|
|
|
|
use serde::Deserialize;
|
|
|
|
fn default_true() -> bool {
|
|
true
|
|
}
|
|
|
|
/// A single stage within a flow (one processor).
|
|
#[derive(Debug, Clone, Deserialize)]
|
|
pub struct Stage {
|
|
pub name: String,
|
|
#[serde(default)]
|
|
pub processor_type: String,
|
|
/// `true` = may run concurrently / dispatched to a background task (non-blocking).
|
|
/// `false` = sequential, the caller waits for completion.
|
|
#[serde(default = "default_true")]
|
|
pub parallel: bool,
|
|
#[serde(default)]
|
|
pub dependencies: Vec<String>,
|
|
#[serde(default)]
|
|
pub enabled: bool,
|
|
#[serde(default)]
|
|
pub timeout_secs: u64,
|
|
}
|
|
|
|
/// An ordered collection of stages (e.g. the `register` flow).
|
|
#[derive(Debug, Clone, Deserialize, Default)]
|
|
pub struct Flow {
|
|
#[serde(default)]
|
|
pub name: String,
|
|
#[serde(default)]
|
|
pub enabled: bool,
|
|
#[serde(default)]
|
|
pub stages: Vec<Stage>,
|
|
}
|
|
|
|
/// A phase grouping (used for the progress UI and concurrency ceilings).
|
|
#[derive(Debug, Clone, Deserialize, Default)]
|
|
pub struct Phase {
|
|
#[serde(default)]
|
|
pub id: i64,
|
|
#[serde(default)]
|
|
pub name_en: Option<String>,
|
|
#[serde(default)]
|
|
pub parallel_strategy: String,
|
|
#[serde(default)]
|
|
pub max_concurrent: Option<u32>,
|
|
#[serde(default)]
|
|
pub processors: Vec<String>,
|
|
}
|
|
|
|
/// Root of `config/pipeline_flows.json`.
|
|
#[derive(Debug, Clone, Deserialize, Default)]
|
|
pub struct PipelineFlows {
|
|
#[serde(default)]
|
|
pub version: String,
|
|
#[serde(default)]
|
|
pub enabled: bool,
|
|
#[serde(default)]
|
|
pub max_concurrent_stages: u32,
|
|
#[serde(default)]
|
|
pub default_timeout_secs: u64,
|
|
#[serde(default)]
|
|
pub phases: Vec<Phase>,
|
|
#[serde(default)]
|
|
pub flows: HashMap<String, Flow>,
|
|
}
|
|
|
|
static CONFIG: OnceLock<PipelineFlows> = OnceLock::new();
|
|
|
|
/// Get the loaded pipeline flow configuration (loaded once, cached).
|
|
pub fn get() -> &'static PipelineFlows {
|
|
CONFIG.get_or_init(load)
|
|
}
|
|
|
|
fn load() -> PipelineFlows {
|
|
let candidates = [
|
|
crate::core::path_utils::config_dir().join("pipeline_flows.json"),
|
|
std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("config/pipeline_flows.json"),
|
|
];
|
|
for path in candidates {
|
|
match std::fs::read_to_string(&path) {
|
|
Ok(s) => match serde_json::from_str::<PipelineFlows>(&s) {
|
|
Ok(cfg) => {
|
|
tracing::info!(
|
|
"pipeline_config: loaded {} (version={}, {} flows)",
|
|
path.display(),
|
|
cfg.version,
|
|
cfg.flows.len()
|
|
);
|
|
return cfg;
|
|
}
|
|
Err(e) => {
|
|
tracing::warn!("pipeline_config: failed to parse {}: {}", path.display(), e)
|
|
}
|
|
},
|
|
Err(_) => continue,
|
|
}
|
|
}
|
|
tracing::warn!("pipeline_config: pipeline_flows.json not found, using defaults");
|
|
PipelineFlows {
|
|
default_timeout_secs: 3600,
|
|
..Default::default()
|
|
}
|
|
}
|
|
|
|
impl PipelineFlows {
|
|
/// Look up a stage by flow name and stage/processor name.
|
|
pub fn stage(&self, flow: &str, name: &str) -> Option<&Stage> {
|
|
self.flows.get(flow)?.stages.iter().find(|s| s.name == name)
|
|
}
|
|
|
|
/// Whether a stage is declared to run in parallel (non-blocking).
|
|
///
|
|
/// Unknown stages default to `true` (parallel / non-blocking) so that a
|
|
/// missing config entry never reintroduces blocking behavior.
|
|
pub fn is_parallel(&self, flow: &str, name: &str) -> bool {
|
|
self.stage(flow, name).map(|s| s.parallel).unwrap_or(true)
|
|
}
|
|
|
|
/// Declared dependencies for a stage (empty when unknown).
|
|
pub fn dependencies(&self, flow: &str, name: &str) -> Vec<String> {
|
|
self.stage(flow, name)
|
|
.map(|s| s.dependencies.clone())
|
|
.unwrap_or_default()
|
|
}
|
|
|
|
/// Effective timeout for a stage (falls back to `default_timeout_secs`).
|
|
pub fn timeout_secs(&self, flow: &str, name: &str) -> u64 {
|
|
self.stage(flow, name)
|
|
.map(|s| s.timeout_secs)
|
|
.filter(|&t| t > 0)
|
|
.unwrap_or(self.default_timeout_secs)
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn test_unknown_stage_defaults_parallel() {
|
|
let cfg = PipelineFlows::default();
|
|
assert!(cfg.is_parallel("register", "does_not_exist"));
|
|
assert!(cfg.dependencies("register", "does_not_exist").is_empty());
|
|
}
|
|
|
|
#[test]
|
|
fn test_scene_declared_parallel() {
|
|
// The shipped config declares the scene stage as parallel.
|
|
let cfg = get();
|
|
assert!(
|
|
cfg.is_parallel("register", "scene"),
|
|
"scene stage must be parallel in pipeline_flows.json"
|
|
);
|
|
assert_eq!(
|
|
cfg.dependencies("register", "scene"),
|
|
vec!["cut".to_string()]
|
|
);
|
|
}
|
|
}
|