feat(schedule): 新增平台任务参数契约与动态选项支持
This commit is contained in:
1 parent
2ce1aca023
commit
8b5b0b49bf
76 files changed
+7103
-1203
No files matched your search
@@ -2,8 +2,10 @@
|
||||
backend/app/services/schedule/schedule_contract.py
|
||||
|
||||
用途:排程三层语义校验与旧数据迁移(schedule_type / data_source_type / platform_api_path)。
|
||||
依赖:job_registry.get_platform_job。
|
||||
逻辑:scheduler_service、api/schedule/tasks、import_service 创建/更新/导入前调用。
|
||||
依赖:job_registry.get_platform_job(含 enabled 停用判定,含 config 白名单)。
|
||||
逻辑:scheduler_service、api/schedule/tasks、import_service 创建/更新/导入前调用;
|
||||
enabled=False 的平台任务在契约校验阶段即拒绝新建/改指向;
|
||||
platform_job_allows_config 同步要求 registry enabled,禁止给停用任务写 ScheduleTaskConfig。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -31,8 +33,19 @@ PLATFORM_JOBS_ALLOWING_CONFIG = frozenset({"shipping-inventory-rpa"})
|
||||
|
||||
|
||||
def platform_job_allows_config(key: str | None) -> bool:
|
||||
"""判断该 platform_job 是否允许写 ScheduleTaskConfig。"""
|
||||
return normalize_job_key(key) in PLATFORM_JOBS_ALLOWING_CONFIG
|
||||
"""
|
||||
判断该 platform_job 是否允许写 ScheduleTaskConfig。
|
||||
|
||||
核心逻辑:须在白名单内,且 registry 中存在且 enabled=True。
|
||||
停用任务与创建/更新/执行一致,禁止继续改其 ScheduleTaskConfig。
|
||||
"""
|
||||
normalized = normalize_job_key(key)
|
||||
if normalized not in PLATFORM_JOBS_ALLOWING_CONFIG:
|
||||
return False
|
||||
from app.services.schedule.job_registry import get_platform_job
|
||||
|
||||
definition = get_platform_job(normalized)
|
||||
return bool(definition and definition.enabled)
|
||||
|
||||
|
||||
def assert_schedule_config_writable(
|
||||
@@ -44,7 +57,7 @@ def assert_schedule_config_writable(
|
||||
"""
|
||||
携带 config 时校验是否允许写入 ScheduleTaskConfig。
|
||||
Raises:
|
||||
ValueError: 非白名单 platform_job 携带 config
|
||||
ValueError: 非白名单 / 已停用 platform_job 携带 config
|
||||
"""
|
||||
if not config or not isinstance(config, dict):
|
||||
return
|
||||
@@ -156,11 +169,11 @@ def validate_schedule_fields(
|
||||
Args:
|
||||
schedule_type: data_pipeline | platform_job
|
||||
data_source_type: 仅 data_pipeline 必填
|
||||
platform_api_path: 仅 platform_job 必填且须已注册
|
||||
platform_api_path: 仅 platform_job 必填且须已注册且 enabled
|
||||
Returns:
|
||||
(schedule_type, data_source_type, platform_api_path)
|
||||
Raises:
|
||||
ValueError: schedule_type 未知、字段组合非法或未注册 job key
|
||||
ValueError: schedule_type 未知、字段组合非法、未注册或已停用 job key
|
||||
"""
|
||||
st = str(schedule_type or "").strip().lower()
|
||||
if st not in VALID_SCHEDULE_TYPES:
|
||||
@@ -180,8 +193,12 @@ def validate_schedule_fields(
|
||||
raise ValueError("platform_api_path is required for platform_job")
|
||||
from app.services.schedule.job_registry import get_platform_job
|
||||
|
||||
if not get_platform_job(path):
|
||||
definition = get_platform_job(path)
|
||||
if not definition:
|
||||
raise ValueError(f"Unknown platform job key: {path}")
|
||||
# enabled=False 表示任务停用:不可新建/改指向该 key(列表接口也不展示)
|
||||
if not definition.enabled:
|
||||
raise ValueError(f"Platform job is disabled: {path}")
|
||||
return st, None, path
|
||||
|
||||
raise ValueError(f"Unsupported schedule_type: {schedule_type}")
|
||||
|
||||
Reference in new issue
Block a user