fix: pipeline log 寫入 output root + processor-counts/json 使用 per-library 路徑
- write_pipeline_timeline: log 寫到 ~/momentry/output (parent of per-lib dir) - get_processor_counts: 用 get_output_dir_for_file + global fallback - get_processor_json: 加 State, per-library 優先 + global fallback - delete_output_files_for_uuid: 同時掃 output root 清 pipeline log
This commit is contained in:
+31
-11
@@ -25,6 +25,14 @@ use crate::{Embedder, FileManager};
|
||||
|
||||
fn delete_output_files_for_uuid(uuid: &str, output_dir: &str) -> u64 {
|
||||
let mut deleted_count = 0u64;
|
||||
// Also scan output root (parent of per-library dir) for pipeline logs
|
||||
let mut dirs = vec![output_dir.to_string()];
|
||||
if let Some(parent) = std::path::Path::new(output_dir).parent() {
|
||||
if parent.file_name().and_then(|n| n.to_str()) == Some("output") {
|
||||
dirs.push(parent.to_string_lossy().to_string());
|
||||
}
|
||||
}
|
||||
for output_dir in &dirs {
|
||||
if let Ok(entries) = std::fs::read_dir(output_dir) {
|
||||
for entry in entries.flatten() {
|
||||
let path = entry.path();
|
||||
@@ -41,6 +49,7 @@ fn delete_output_files_for_uuid(uuid: &str, output_dir: &str) -> u64 {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
deleted_count
|
||||
}
|
||||
|
||||
@@ -999,6 +1008,7 @@ async fn get_output_completeness(
|
||||
}
|
||||
|
||||
async fn get_processor_json(
|
||||
State(state): State<AppState>,
|
||||
Query(params): Query<std::collections::HashMap<String, String>>,
|
||||
) -> Result<Json<serde_json::Value>, (StatusCode, Json<serde_json::Value>)> {
|
||||
let file_uuid = params.get("file_hash").ok_or((
|
||||
@@ -1023,8 +1033,16 @@ async fn get_processor_json(
|
||||
"tkg" => "tkg",
|
||||
other => other,
|
||||
};
|
||||
let output_dir = crate::core::config::OUTPUT_DIR.as_str();
|
||||
let path = format!("{}/{}.{}.json", output_dir.trim_end_matches('/'), file_uuid, ext);
|
||||
// Try per-library dir first, then global OUTPUT_DIR (legacy)
|
||||
let per_lib_dir = crate::core::config::get_output_dir_for_file(file_uuid, state.db.pool()).await;
|
||||
let global_dir = crate::core::config::OUTPUT_DIR.as_str();
|
||||
let candidates = [
|
||||
format!("{}/{}.{}.json", per_lib_dir.trim_end_matches('/'), file_uuid, ext),
|
||||
format!("{}/{}.{}.json", global_dir.trim_end_matches('/'), file_uuid, ext),
|
||||
];
|
||||
let path = candidates.iter().find(|p| std::path::Path::new(p).exists())
|
||||
.cloned()
|
||||
.unwrap_or_else(|| candidates[0].clone());
|
||||
|
||||
match std::fs::read_to_string(&path) {
|
||||
Ok(content) => match serde_json::from_str(&content) {
|
||||
@@ -1067,37 +1085,39 @@ async fn get_processor_counts(
|
||||
});
|
||||
|
||||
let file_uuid = full_uuid.ok_or(StatusCode::NOT_FOUND)?;
|
||||
let output_dir = crate::core::config::OUTPUT_DIR.to_string();
|
||||
// Use per-library output dir (test files live in output/test, not output/demo)
|
||||
let per_lib_dir = crate::core::config::get_output_dir_for_file(&file_uuid, state.db.pool()).await;
|
||||
let global_dir = crate::core::config::OUTPUT_DIR.as_str();
|
||||
|
||||
let processors = crate::core::db::ProcessorType::all();
|
||||
let mut results = Vec::new();
|
||||
|
||||
for processor in &processors {
|
||||
let proc_name = processor.as_str();
|
||||
// resolve output filename: some processors write under a different
|
||||
// extension than their queue name (face_trace → face_traced.json).
|
||||
let json_ext = match proc_name {
|
||||
"face_trace" => "face_traced",
|
||||
other => other,
|
||||
};
|
||||
let json_path =
|
||||
std::path::Path::new(&output_dir).join(format!("{}.{}.json", file_uuid, json_ext));
|
||||
let filename = format!("{}.{}.json", file_uuid, json_ext);
|
||||
let json_path = std::path::Path::new(&per_lib_dir).join(&filename);
|
||||
let fallback_path = std::path::Path::new(global_dir).join(&filename);
|
||||
let effective_path = if json_path.exists() { json_path } else { fallback_path };
|
||||
|
||||
let has_json = json_path.exists();
|
||||
let has_json = effective_path.exists();
|
||||
let mut frame_count = None;
|
||||
let mut segment_count = None;
|
||||
let mut chunk_count = None;
|
||||
let mut last_modified = None;
|
||||
|
||||
if has_json {
|
||||
if let Ok(metadata) = std::fs::metadata(&json_path) {
|
||||
if let Ok(metadata) = std::fs::metadata(&effective_path) {
|
||||
if let Ok(modified) = metadata.modified() {
|
||||
let chrono_dt: chrono::DateTime<chrono::Utc> = modified.into();
|
||||
last_modified = Some(chrono_dt.to_rfc3339());
|
||||
}
|
||||
}
|
||||
|
||||
if let Ok(content) = std::fs::read_to_string(&json_path) {
|
||||
if let Ok(content) = std::fs::read_to_string(&effective_path) {
|
||||
if let Ok(json) = serde_json::from_str::<serde_json::Value>(&content) {
|
||||
// CUT: prioritize scenes count over frame_count
|
||||
if proc_name == "cut" {
|
||||
@@ -1166,7 +1186,7 @@ async fn get_processor_counts(
|
||||
|
||||
Ok(Json(ProcessorCountsResponse {
|
||||
file_uuid,
|
||||
output_dir,
|
||||
output_dir: per_lib_dir,
|
||||
processors: results,
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -3976,8 +3976,14 @@ pub async fn get_session_by_id(
|
||||
"processor": processor,
|
||||
"status": status,
|
||||
});
|
||||
let path = std::path::Path::new(crate::core::config::OUTPUT_DIR.as_str())
|
||||
.join(format!("pipeline_{}.log", uuid));
|
||||
// Pipeline timeline logs go to the output ROOT (parent of per-library dir).
|
||||
// OUTPUT_DIR may be a per-library dir like output/demo — strip it to output/.
|
||||
let output_root = std::path::Path::new(crate::core::config::OUTPUT_DIR.as_str())
|
||||
.parent()
|
||||
.filter(|p| p.file_name().and_then(|n| n.to_str()) == Some("output"))
|
||||
.map(|p| p.to_path_buf())
|
||||
.unwrap_or_else(|| std::path::PathBuf::from(crate::core::config::OUTPUT_DIR.as_str()));
|
||||
let path = output_root.join(format!("pipeline_{}.log", uuid));
|
||||
if let Ok(mut file) = std::fs::OpenOptions::new()
|
||||
.create(true)
|
||||
.append(true)
|
||||
|
||||
Reference in New Issue
Block a user