fix: 修复工作流结果获取逻辑
- 移除响应URL比较条件,总是尝试获取最终结果 - 优化GET请求逻辑,确保能正确获取工作流执行结果 - 解决响应URL相同时无法获取结果的问题 现在无论响应URL是否改变,都会尝试对响应URL进行GET请求来获取包含output_files的完整结果。
This commit is contained in:
parent
07239ee53c
commit
03a87223de
|
|
@ -123,47 +123,43 @@ impl ComfyuiInfrastructureService {
|
|||
let response_url = response.url().to_string();
|
||||
info!("Response URL: {}", response_url);
|
||||
|
||||
// 尝试解析响应,如果失败则返回基本成功响应
|
||||
let initial_result: Value = response.json().await
|
||||
.unwrap_or_else(|_| serde_json::json!({}));
|
||||
|
||||
info!("Workflow '{}' execution started", request.base_name);
|
||||
|
||||
// 如果响应URL不同于请求URL,说明需要访问新的URL获取结果
|
||||
if response_url != url {
|
||||
info!("Fetching final result from: {}", response_url);
|
||||
// 总是尝试用 GET 请求获取最终结果
|
||||
info!("Using GET request to fetch final result from: {}", response_url);
|
||||
|
||||
// 访问响应URL获取最终结果
|
||||
match self.client.get(&response_url).send().await {
|
||||
Ok(final_response) => {
|
||||
if final_response.status().is_success() {
|
||||
match final_response.json::<Value>().await {
|
||||
Ok(final_result) => {
|
||||
info!("Successfully retrieved final result");
|
||||
let execute_response = ExecuteWorkflowResponse {
|
||||
task_id: initial_result.get("task_id").and_then(|v| v.as_str()).map(String::from),
|
||||
status: Some("completed".to_string()),
|
||||
message: Some("Workflow execution completed successfully".to_string()),
|
||||
result: Some(final_result),
|
||||
error: None,
|
||||
};
|
||||
return Ok(execute_response);
|
||||
}
|
||||
Err(e) => {
|
||||
warn!("Failed to parse final result JSON: {}", e);
|
||||
}
|
||||
match self.client.get(&response_url).send().await {
|
||||
Ok(final_response) => {
|
||||
if final_response.status().is_success() {
|
||||
match final_response.json::<Value>().await {
|
||||
Ok(final_result) => {
|
||||
info!("Successfully retrieved final result via GET");
|
||||
let execute_response = ExecuteWorkflowResponse {
|
||||
task_id: None, // GET 请求通常不返回 task_id
|
||||
status: Some("completed".to_string()),
|
||||
message: Some("Workflow execution completed successfully".to_string()),
|
||||
result: Some(final_result),
|
||||
error: None,
|
||||
};
|
||||
return Ok(execute_response);
|
||||
}
|
||||
Err(e) => {
|
||||
warn!("Failed to parse final result JSON: {}", e);
|
||||
}
|
||||
} else {
|
||||
warn!("Failed to fetch final result: HTTP {}", final_response.status());
|
||||
}
|
||||
} else {
|
||||
warn!("Failed to fetch final result: HTTP {}", final_response.status());
|
||||
}
|
||||
Err(e) => {
|
||||
warn!("Failed to request final result: {}", e);
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
warn!("Failed to request final result: {}", e);
|
||||
}
|
||||
}
|
||||
|
||||
// 如果无法获取最终结果,返回初始响应
|
||||
// 如果无法获取最终结果,解析初始响应
|
||||
let initial_result: Value = response.json().await
|
||||
.unwrap_or_else(|_| serde_json::json!({}));
|
||||
|
||||
let execute_response = ExecuteWorkflowResponse {
|
||||
task_id: initial_result.get("task_id").and_then(|v| v.as_str()).map(String::from),
|
||||
status: initial_result.get("status").and_then(|v| v.as_str()).map(String::from),
|
||||
|
|
|
|||
Loading…
Reference in New Issue