feat: 完成input_context节点

This commit is contained in:
2026-09-22 19:12:31 +08:00
parent 9bddbc3aa5
commit 4d46336bc2
14 changed files with 229 additions and 14 deletions
+17 -6
View File
@@ -1,9 +1,12 @@
import logging
import time
from abc import ABC, abstractmethod
from typing import TypeVar
from typing import TYPE_CHECKING, TypeVar
from app.config import Settings, settings
from pydantic import ValidationError
if TYPE_CHECKING:
from app.config import Settings
from app.exceptions import AppError, ImportProcessError
T = TypeVar("T")
@@ -12,18 +15,26 @@ T = TypeVar("T")
class BaseNode(ABC):
name: str = "base_node"
def __init__(self, config: Settings | None = None):
"""传入配置时使用传入值,否则使用全局配置"""
self.config = config if config is not None else settings
def __init__(self, config: "Settings | None" = None):
"""保存显式配置;全局配置在节点实际使用时才加载。"""
self._config = config
self.logger = logging.getLogger(f"import.{self.name}")
@property
def config(self) -> "Settings":
if self._config is None:
from app.config import settings
self._config = settings
return self._config
def __call__(self, state: T) -> T:
"""执行节点,统一记录日志、耗时并保留业务异常类型"""
start_time = time.perf_counter()
self.logger.info("--- %s 开始 ---", self.name)
try:
result = self.process(state)
except AppError:
except (AppError, ValidationError):
self.logger.exception("%s 执行失败", self.name)
raise
except Exception as e: