chronaxis.batch.config
源码基线:8904c2f744951857659abd40aaa3535d57faf53c
1"""加载批量清单;显式jobs保存路径,template展开为每文件独立计划。23JSON/YAML重复键、非有限值和错误定位沿用共享配置语法规则;实际独立计划到4jobs在worker启动时加载;template在此时读取模板和必要DBC元数据,均不预读业务日志。5"""67from pathlib import Path8from ..configuration import load_configuration, ConfigurationError9from ..configuration.diagnostics import locate_error10from ..planning.checks import PlanValidationError, configuration_error11from .models import BatchPlan121314def load_batch_plan(path: str | Path) -> BatchPlan:15 """读取批量YAML或JSON文件,建立独立任务及其调度设置。1617 参数:18 path (str | Path): UTF-8批量配置路径;子计划相对路径以本文件目录为起点。19 返回:20 BatchPlan: 已检查批量结构的不可变计划;template已展开,jobs仍保存路径,均未读取业务输入。21 异常:22 PlanValidationError: 路径类型不合法、文件不可读、编码/语法错误或批量字段不合法。23 先按错误字段路径修正批量或模板文件;jobs中的子计划错误在任务启动时记入任务报告。24 副作用:25 读取批量文件,template模式还读取模板与必要DBC、枚举输入集合;不创建输出目录。"""26 if not isinstance(path, (str, Path)):27 raise PlanValidationError('$', '批量配置路径必须为Path或文本')28 target = Path(path).absolute()29 try:30 document = load_configuration(target)31 return BatchPlan.from_dict(document.data, base_dir=target.parent)32 except ConfigurationError as error:33 raise configuration_error(error) from error34 except PlanValidationError as error:35 raise locate_error(error,document)36 except (OSError, UnicodeError, ValueError, TypeError) as error:37 raise PlanValidationError('$',str(error),'load_error',source=str(target)) from error38