fix: cargo check --lib error
This commit is contained in:
parent
d66b8dd9f8
commit
d85bde176b
|
|
@ -332,7 +332,7 @@ impl AppState {
|
|||
|
||||
/// 初始化 ComfyUI Infrastructure 服务
|
||||
pub fn initialize_comfyui_service(&self, config: crate::data::models::comfyui::ComfyUIConfig) -> anyhow::Result<()> {
|
||||
let service = ComfyuiInfrastructureService::new(config)?;
|
||||
let service = ComfyuiInfrastructureService::new(config.to_legacy_config())?;
|
||||
|
||||
let mut comfyui_service = self.comfyui_infrastructure_service.lock()
|
||||
.map_err(|e| anyhow::anyhow!("Failed to acquire lock for ComfyUI Infrastructure service: {}", e))?;
|
||||
|
|
@ -357,7 +357,7 @@ impl AppState {
|
|||
/// 更新 ComfyUI Infrastructure 服务配置
|
||||
pub async fn update_comfyui_config(&self, config: crate::data::models::comfyui::ComfyUIConfig) -> anyhow::Result<()> {
|
||||
// 创建新的服务实例
|
||||
let new_service = ComfyuiInfrastructureService::new(config)?;
|
||||
let new_service = ComfyuiInfrastructureService::new(config.to_legacy_config())?;
|
||||
|
||||
// 更新服务
|
||||
let mut comfyui_service = self.comfyui_infrastructure_service.lock()
|
||||
|
|
|
|||
|
|
@ -300,7 +300,7 @@ pub enum ConfigHealthStatus {
|
|||
/// 健康
|
||||
Healthy,
|
||||
/// 不健康
|
||||
Unhealthy(Vec<crate::data::models::comfyui::ValidationError>),
|
||||
Unhealthy(Vec<crate::data::models::comfyui::SDKValidationError>),
|
||||
}
|
||||
|
||||
impl std::fmt::Display for ConfigHealthStatus {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use tracing::{error, warn, info, debug};
|
|||
use serde::{Serialize, Deserialize};
|
||||
|
||||
/// 统一错误类型
|
||||
#[derive(Debug, thiserror::Error, Clone, Serialize, Deserialize)]
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum ComfyUIError {
|
||||
/// 连接错误
|
||||
#[error("连接错误: {message}")]
|
||||
|
|
@ -73,10 +73,10 @@ impl ComfyUIError {
|
|||
ComfyUIError::ResourceExhausted { .. } => true,
|
||||
ComfyUIError::Sdk(sdk_error) => {
|
||||
// 根据 SDK 错误类型判断是否可重试
|
||||
matches!(sdk_error,
|
||||
comfyui_sdk::error::ComfyUIError::Network(_) |
|
||||
matches!(sdk_error,
|
||||
comfyui_sdk::error::ComfyUIError::Http(_) |
|
||||
comfyui_sdk::error::ComfyUIError::Timeout(_) |
|
||||
comfyui_sdk::error::ComfyUIError::ServerError(_)
|
||||
comfyui_sdk::error::ComfyUIError::Connection(_)
|
||||
)
|
||||
}
|
||||
_ => false,
|
||||
|
|
@ -184,7 +184,7 @@ impl ComfyUIError {
|
|||
}
|
||||
|
||||
/// 错误严重程度
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
pub enum ErrorSeverity {
|
||||
/// 低 - 用户可以继续操作
|
||||
Low,
|
||||
|
|
@ -268,7 +268,7 @@ impl ErrorHandler {
|
|||
}
|
||||
|
||||
/// 错误处理结果
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug)]
|
||||
pub struct ErrorHandleResult {
|
||||
pub error: ComfyUIError,
|
||||
pub severity: ErrorSeverity,
|
||||
|
|
|
|||
|
|
@ -135,7 +135,7 @@ impl TemplateModel {
|
|||
// 检查必需参数
|
||||
for (param_name, schema) in &self.parameter_schema {
|
||||
if schema.required.unwrap_or(false) && !params.contains_key(param_name) {
|
||||
result.add_error(ValidationError::new(
|
||||
result.add_error(SDKValidationError::new(
|
||||
param_name,
|
||||
format!("Required parameter '{}' is missing", param_name)
|
||||
));
|
||||
|
|
@ -155,14 +155,14 @@ impl TemplateModel {
|
|||
}
|
||||
|
||||
/// 验证单个参数值
|
||||
fn validate_parameter_value(&self, param_name: &str, value: &serde_json::Value, schema: &ParameterSchema) -> Result<(), ValidationError> {
|
||||
fn validate_parameter_value(&self, param_name: &str, value: &serde_json::Value, schema: &ParameterSchema) -> Result<(), SDKValidationError> {
|
||||
match (&schema.param_type, value) {
|
||||
(ParameterType::String, serde_json::Value::String(_)) => Ok(()),
|
||||
(ParameterType::Number, serde_json::Value::Number(_)) => Ok(()),
|
||||
(ParameterType::Boolean, serde_json::Value::Bool(_)) => Ok(()),
|
||||
(ParameterType::Array, serde_json::Value::Array(_)) => Ok(()),
|
||||
(ParameterType::Object, serde_json::Value::Object(_)) => Ok(()),
|
||||
_ => Err(ValidationError::with_value(
|
||||
_ => Err(SDKValidationError::with_value(
|
||||
param_name,
|
||||
format!("Parameter '{}' has invalid type, expected {:?}", param_name, schema.param_type),
|
||||
value.clone()
|
||||
|
|
@ -282,10 +282,19 @@ impl ExecutionModel {
|
|||
self.status = status;
|
||||
if matches!(status, ExecutionStatus::Completed | ExecutionStatus::Failed | ExecutionStatus::Cancelled) {
|
||||
self.completed_at = Some(Utc::now());
|
||||
if let Some(created_at) = self.created_at.timestamp_millis().try_into().ok() {
|
||||
if let Some(completed_at) = self.completed_at.and_then(|t| t.timestamp_millis().try_into().ok()) {
|
||||
self.execution_time = Some(completed_at - created_at);
|
||||
}
|
||||
let created_at_millis = self.created_at.timestamp_millis();
|
||||
let created_at: u64 = match created_at_millis.try_into() {
|
||||
Ok(val) => val,
|
||||
Err(_) => return,
|
||||
};
|
||||
|
||||
if let Some(completed_at_time) = self.completed_at {
|
||||
let completed_at_millis = completed_at_time.timestamp_millis();
|
||||
let completed_at: u64 = match completed_at_millis.try_into() {
|
||||
Ok(val) => val,
|
||||
Err(_) => return,
|
||||
};
|
||||
self.execution_time = Some(completed_at - created_at);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -511,32 +520,43 @@ impl ComfyUIConfig {
|
|||
}
|
||||
}
|
||||
|
||||
/// 转换为旧版 Infrastructure 配置
|
||||
pub fn to_legacy_config(&self) -> ComfyuiConfig {
|
||||
ComfyuiConfig {
|
||||
base_url: self.base_url.clone(),
|
||||
timeout: Some(self.timeout_seconds),
|
||||
retry_attempts: Some(self.retry_attempts),
|
||||
enable_cache: Some(self.enable_cache),
|
||||
max_concurrency: Some(self.max_concurrency),
|
||||
}
|
||||
}
|
||||
|
||||
/// 验证配置
|
||||
pub fn validate(&self) -> ValidationResult {
|
||||
let mut result = ValidationResult::success();
|
||||
|
||||
// 验证 URL
|
||||
if self.base_url.is_empty() {
|
||||
result.add_error(SDKValidationError::new("base_url".to_string(), "Base URL cannot be empty".to_string(), None));
|
||||
result.add_error(SDKValidationError::new("base_url".to_string(), "Base URL cannot be empty".to_string()));
|
||||
} else if url::Url::parse(&self.base_url).is_err() {
|
||||
result.add_error(SDKValidationError::new("base_url".to_string(), "Invalid URL format".to_string(), None));
|
||||
result.add_error(SDKValidationError::new("base_url".to_string(), "Invalid URL format".to_string()));
|
||||
}
|
||||
|
||||
// 验证超时时间
|
||||
if self.timeout_seconds == 0 {
|
||||
result.add_error(SDKValidationError::new("timeout_seconds".to_string(), "Timeout must be greater than 0".to_string(), None));
|
||||
result.add_error(SDKValidationError::new("timeout_seconds".to_string(), "Timeout must be greater than 0".to_string()));
|
||||
}
|
||||
|
||||
// 验证重试次数
|
||||
if self.retry_attempts > 10 {
|
||||
result.add_error(SDKValidationError::new("retry_attempts".to_string(), "Retry attempts should not exceed 10".to_string(), None));
|
||||
result.add_error(SDKValidationError::new("retry_attempts".to_string(), "Retry attempts should not exceed 10".to_string()));
|
||||
}
|
||||
|
||||
// 验证并发数
|
||||
if self.max_concurrency == 0 {
|
||||
result.add_error(SDKValidationError::new("max_concurrency".to_string(), "Max concurrency must be greater than 0".to_string(), None));
|
||||
result.add_error(SDKValidationError::new("max_concurrency".to_string(), "Max concurrency must be greater than 0".to_string()));
|
||||
} else if self.max_concurrency > 100 {
|
||||
result.add_error(SDKValidationError::new("max_concurrency".to_string(), "Max concurrency should not exceed 100".to_string(), None));
|
||||
result.add_error(SDKValidationError::new("max_concurrency".to_string(), "Max concurrency should not exceed 100".to_string()));
|
||||
}
|
||||
|
||||
result
|
||||
|
|
@ -739,7 +759,7 @@ pub enum ComfyuiError {
|
|||
/// HTTP 错误
|
||||
HttpError { status: u16, message: String },
|
||||
/// 验证错误
|
||||
ValidationError { errors: Vec<ValidationError> },
|
||||
ValidationError { errors: Vec<SDKValidationError> },
|
||||
/// 服务器内部错误
|
||||
ServerError { message: String },
|
||||
/// 工作流不存在
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ impl ComfyuiInfrastructureService {
|
|||
}
|
||||
|
||||
/// 获取配置信息
|
||||
pub fn get_config(&self) -> &ComfyUIConfig {
|
||||
pub fn get_config(&self) -> &ComfyuiConfig {
|
||||
&self.config
|
||||
}
|
||||
|
||||
|
|
@ -347,12 +347,14 @@ impl ComfyuiInfrastructureService {
|
|||
|
||||
/// 更新服务配置
|
||||
pub fn update_config(&mut self, config: ComfyUIConfig) -> Result<()> {
|
||||
let legacy_config = config.to_legacy_config();
|
||||
|
||||
// 验证新配置
|
||||
let temp_service = Self::new(config.clone())?;
|
||||
let temp_service = Self::new(legacy_config.clone())?;
|
||||
temp_service.validate_config()?;
|
||||
|
||||
// 更新配置和客户端
|
||||
self.config = config;
|
||||
self.config = legacy_config;
|
||||
let timeout = Duration::from_secs(self.config.timeout.unwrap_or(30));
|
||||
self.client = Client::builder()
|
||||
.timeout(timeout)
|
||||
|
|
|
|||
|
|
@ -592,7 +592,7 @@ pub fn run() {
|
|||
commands::comfyui_v2_commands::comfyui_v2_get_connection_status,
|
||||
commands::comfyui_v2_commands::comfyui_v2_health_check,
|
||||
commands::comfyui_v2_commands::comfyui_v2_get_system_info,
|
||||
commands::comfyui_v2_commands::comfyui_v2_get_queue_status,
|
||||
commands::comfyui_v2_commands::comfyui_v2_get_queue_basic_status,
|
||||
commands::comfyui_v2_commands::comfyui_v2_get_config,
|
||||
commands::comfyui_v2_commands::comfyui_v2_update_config,
|
||||
commands::comfyui_v2_commands::comfyui_v2_validate_config,
|
||||
|
|
|
|||
|
|
@ -181,12 +181,12 @@ pub async fn comfyui_v2_get_system_info(
|
|||
Err("功能暂未实现".to_string())
|
||||
}
|
||||
|
||||
/// 获取队列状态
|
||||
/// 获取队列基本状态
|
||||
#[tauri::command]
|
||||
pub async fn comfyui_v2_get_queue_status(
|
||||
pub async fn comfyui_v2_get_queue_basic_status(
|
||||
state: State<'_, AppState>,
|
||||
) -> Result<QueueStatusResponse, String> {
|
||||
info!("Command: comfyui_v2_get_queue_status");
|
||||
info!("Command: comfyui_v2_get_queue_basic_status");
|
||||
|
||||
// TODO: 从管理器获取队列状态
|
||||
Ok(QueueStatusResponse {
|
||||
|
|
@ -514,7 +514,9 @@ fn convert_workflow_model(workflow: &WorkflowModel) -> WorkflowResponse {
|
|||
id: workflow.id.clone(),
|
||||
name: workflow.name.clone(),
|
||||
description: workflow.description.clone(),
|
||||
workflow_data: workflow.workflow_data.clone(),
|
||||
workflow_data: workflow.workflow_data.iter()
|
||||
.map(|(k, v)| (k.clone(), serde_json::to_value(v).unwrap_or(serde_json::Value::Null)))
|
||||
.collect(),
|
||||
version: workflow.version.clone(),
|
||||
created_at: workflow.created_at.to_rfc3339(),
|
||||
updated_at: workflow.updated_at.to_rfc3339(),
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ use tracing::{info, warn, error, debug};
|
|||
|
||||
use crate::app_state::AppState;
|
||||
use crate::business::services::{
|
||||
realtime_monitor_v2::{RealtimeMonitorV2, RealtimeMonitorConfig, ConnectionStatus, EventStatistics, MonitorStatsV2},
|
||||
realtime_monitor_v2::{RealtimeMonitorV2, RealtimeMonitorConfig, ConnectionStatus, EventStatistics},
|
||||
tauri_event_emitter::TauriEventEmitter,
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue