feat: add trigger source and reason logging to unregister
Now all unregister operations log: - source: who triggered it (api, studio, watcher, auto-cleanup, etc.) - reason: why it was triggered (manual, failed-processing, duplicate, etc.) Also adds proper ERROR logging for failures: - Transaction commit failures - Redis client creation failures - Qdrant deletion failures This allows tracking which operations caused file deletion and identifying failures that were previously silent.
This commit is contained in:
+29
-9
@@ -1045,6 +1045,10 @@ struct UnregisterRequest {
|
||||
file_path: Option<String>,
|
||||
#[serde(default)]
|
||||
async_mode: bool,
|
||||
#[serde(default)]
|
||||
trigger_source: Option<String>,
|
||||
#[serde(default)]
|
||||
reason: Option<String>,
|
||||
}
|
||||
|
||||
fn delete_output_files(uuid: &str) -> u64 {
|
||||
@@ -1114,10 +1118,12 @@ async fn unregister(
|
||||
None => return Err(StatusCode::BAD_REQUEST),
|
||||
};
|
||||
|
||||
let source = req.trigger_source.as_deref().unwrap_or("unknown");
|
||||
let reason = req.reason.as_deref().unwrap_or("unspecified");
|
||||
|
||||
tracing::info!(
|
||||
"[UNREGISTER] Unregistering file: {} (async_mode={})",
|
||||
uuid,
|
||||
req.async_mode
|
||||
"[UNREGISTER] Trigger: source={}, reason={}. Unregistering file: {} (async_mode={})",
|
||||
source, reason, uuid, req.async_mode
|
||||
);
|
||||
|
||||
// Async mode: spawn background task and return immediately
|
||||
@@ -1125,17 +1131,22 @@ async fn unregister(
|
||||
let job_id = format!("unregister_{}", uuid);
|
||||
let state_clone = state.clone();
|
||||
let uuid_clone = uuid.clone();
|
||||
let source_clone = source.to_string();
|
||||
let reason_clone = reason.to_string();
|
||||
tokio::spawn(async move {
|
||||
tracing::info!(
|
||||
"[ASYNC_UNREGISTER] Starting background unregister for {}",
|
||||
uuid_clone
|
||||
"[ASYNC_UNREGISTER] Starting background unregister for {} (source={}, reason={})",
|
||||
uuid_clone, source_clone, reason_clone
|
||||
);
|
||||
match unregister_internal(&state_clone, &uuid_clone).await {
|
||||
Ok(()) => {
|
||||
tracing::info!("[ASYNC_UNREGISTER] Completed for {}", uuid_clone);
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::error!("[ASYNC_UNREGISTER] Failed for {}: {:?}", uuid_clone, e);
|
||||
tracing::error!(
|
||||
"[ASYNC_UNREGISTER] FAILED for {} (source={}, reason={}): {:?}",
|
||||
uuid_clone, source_clone, reason_clone, e
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -1287,7 +1298,10 @@ async fn unregister(
|
||||
})?;
|
||||
|
||||
tx.commit().await.map_err(|e| {
|
||||
tracing::error!("[unregister] Failed to commit transaction: {}", e);
|
||||
tracing::error!(
|
||||
"[UNREGISTER] FAILED to commit transaction for {} (source={}, reason={}): {}",
|
||||
uuid, source, reason, e
|
||||
);
|
||||
StatusCode::INTERNAL_SERVER_ERROR
|
||||
})?;
|
||||
|
||||
@@ -1311,7 +1325,10 @@ async fn unregister(
|
||||
tracing::info!("[UNREGISTER] Deleted Qdrant vectors from main collection");
|
||||
total += 1;
|
||||
} else {
|
||||
tracing::warn!("[UNREGISTER] Failed to delete Qdrant vectors from main collection");
|
||||
tracing::error!(
|
||||
"[UNREGISTER] FAILED to delete Qdrant vectors from main collection for {} (source={})",
|
||||
uuid, source
|
||||
);
|
||||
}
|
||||
|
||||
let additional_collections = [
|
||||
@@ -1386,7 +1403,10 @@ async fn unregister(
|
||||
Some(deleted)
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::warn!("[UNREGISTER] Failed to create Redis client: {}", e);
|
||||
tracing::error!(
|
||||
"[UNREGISTER] FAILED to create Redis client for {} (source={}): {}",
|
||||
uuid, source, e
|
||||
);
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user