feat: ASRX hybrid pipeline, identity history, worker fixes, checkpoint system
This commit is contained in:
@@ -233,50 +233,54 @@ async fn trigger_processing(
|
||||
.await
|
||||
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
|
||||
|
||||
let processors_to_run: Vec<&str> = if let Some(procs) = &req.processors {
|
||||
// 檢查 job 是否存在,不存在則 INSERT(state machine entry)
|
||||
let existing_id: Option<i32> = sqlx::query_scalar(&format!(
|
||||
"SELECT id FROM {monitor_jobs_table} WHERE uuid = $1"
|
||||
))
|
||||
.bind(&file_uuid)
|
||||
.fetch_optional(state.db.pool())
|
||||
.await
|
||||
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
|
||||
|
||||
if existing_id.is_none() {
|
||||
state
|
||||
.db
|
||||
.create_monitor_job(&file_uuid, Some(&file_path))
|
||||
.await
|
||||
.map_err(|e| {
|
||||
tracing::error!(
|
||||
"[TRIGGER] Failed to create monitor job for {}: {}",
|
||||
file_uuid,
|
||||
e
|
||||
);
|
||||
StatusCode::INTERNAL_SERVER_ERROR
|
||||
})?;
|
||||
}
|
||||
|
||||
// UPDATE processors + reset 狀態讓 worker 可 pickup
|
||||
let procs_db: Vec<String> = procs.iter().map(|s| s.to_string()).collect();
|
||||
sqlx::query(&format!(
|
||||
"UPDATE {monitor_jobs_table} SET processors = $1::text[], status = 'pending' WHERE uuid = $2"
|
||||
))
|
||||
.bind(&procs_db)
|
||||
.bind(&file_uuid)
|
||||
.execute(state.db.pool())
|
||||
.await
|
||||
.map_err(|e| {
|
||||
tracing::error!("[TRIGGER] Failed to update monitor job for {}: {}", file_uuid, e);
|
||||
StatusCode::INTERNAL_SERVER_ERROR
|
||||
})?;
|
||||
|
||||
procs.iter().map(|s| s.as_str()).collect()
|
||||
let processors_to_run: Vec<String> = if let Some(procs) = &req.processors {
|
||||
procs.iter().map(|s| s.to_string()).collect()
|
||||
} else {
|
||||
vec![]
|
||||
crate::core::db::ProcessorType::all()
|
||||
.iter()
|
||||
.map(|p| p.as_str().to_string())
|
||||
.collect()
|
||||
};
|
||||
|
||||
// 確保 monitor_job 存在
|
||||
let existing_id: Option<i32> = sqlx::query_scalar(&format!(
|
||||
"SELECT id FROM {monitor_jobs_table} WHERE uuid = $1"
|
||||
))
|
||||
.bind(&file_uuid)
|
||||
.fetch_optional(state.db.pool())
|
||||
.await
|
||||
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
|
||||
|
||||
if existing_id.is_none() {
|
||||
state
|
||||
.db
|
||||
.create_monitor_job(&file_uuid, Some(&file_path))
|
||||
.await
|
||||
.map_err(|e| {
|
||||
tracing::error!(
|
||||
"[TRIGGER] Failed to create monitor job for {}: {}",
|
||||
file_uuid,
|
||||
e
|
||||
);
|
||||
StatusCode::INTERNAL_SERVER_ERROR
|
||||
})?;
|
||||
}
|
||||
|
||||
// UPDATE processors + reset 狀態讓 worker 可 pickup
|
||||
sqlx::query(&format!(
|
||||
"UPDATE {monitor_jobs_table} SET processors = $1::text[], status = 'pending' WHERE uuid = $2"
|
||||
))
|
||||
.bind(&processors_to_run)
|
||||
.bind(&file_uuid)
|
||||
.execute(state.db.pool())
|
||||
.await
|
||||
.map_err(|e| {
|
||||
tracing::error!("[TRIGGER] Failed to update monitor job for {}: {}", file_uuid, e);
|
||||
StatusCode::INTERNAL_SERVER_ERROR
|
||||
})?;
|
||||
|
||||
let processors_to_run_refs: Vec<&str> = processors_to_run.iter().map(|s| s.as_str()).collect();
|
||||
|
||||
let notification = serde_json::json!({
|
||||
"action": "process",
|
||||
"file_uuid": file_uuid,
|
||||
@@ -285,7 +289,7 @@ async fn trigger_processing(
|
||||
"file_type": file_type,
|
||||
"content_hash": content_hash,
|
||||
"output_dir": output_dir,
|
||||
"processors": processors_to_run,
|
||||
"processors": processors_to_run_refs,
|
||||
});
|
||||
|
||||
let notification_key = format!("{}notifications", REDIS_KEY_PREFIX.as_str());
|
||||
|
||||
Reference in New Issue
Block a user