Files
xiaoxia-saas/packages/domain/edit_plan.py
xiaoxia 53fb25efcf
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (push) Successful in 2s
CI/CD Pipeline / Check push changed paths (push) Successful in 19s
CI/CD Pipeline / Build Staging API Image (push) Successful in 41s
CI/CD Pipeline / Build Staging Worker Image (push) Successful in 48s
CI/CD Pipeline / Integration Tests (push) Successful in 3m10s
CI/CD Pipeline / Validate - Python (mypy + alembic) (push) Successful in 3m17s
CI/CD Pipeline / Build Staging Web Image (push) Successful in 3m30s
CI/CD Pipeline / Validate - Style (push) Successful in 4m17s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Successful in 59s
CI/CD Pipeline / Frontend Unit Tests (push) Failing after 5m33s
CI/CD Pipeline / Validate - Security (push) Successful in 7m12s
CI/CD Pipeline / ACR Image Cleanup (push) Successful in 2m38s
CI/CD Pipeline / Staging API Integration Tests (push) Successful in 3m13s
CI/CD Pipeline / Unit Tests (push) Successful in 10m11s
CI/CD Pipeline / Production Browser E2E (push) Has been skipped
CI/CD Pipeline / Staging E2E Tests (push) Has been cancelled
CI/CD Pipeline / Build Production Worker Image (push) Failing after 26h14m3s
CI/CD Pipeline / PR Build Worker Image (push) Failing after 26h24m21s
CI/CD Pipeline / Retag skipped Staging API Image (push) Failing after 26h19m47s
CI/CD Pipeline / PR Build Web Image (push) Failing after 26h23m44s
CI/CD Pipeline / PR Build API Image (push) Failing after 26h23m44s
CI/CD Pipeline / Deploy Production (push) Failing after 26h13m23s
CI/CD Pipeline / Build Production Web Image (push) Failing after 26h13m26s
CI/CD Pipeline / CI Gate (push) Failing after 26h13m25s
CI/CD Pipeline / Build Production API Image (push) Failing after 26h13m26s
CI/CD Pipeline / Canary Release to Production (push) Failing after 26h13m23s
CI/CD Pipeline / Retag skipped Staging Web Image (push) Failing after 26h19m46s
CI/CD Pipeline / Frontend Lint (push) Failing after 26h23m37s
CI/CD Pipeline / Check if frontend-only change (push) Failing after 26h23m45s
CI/CD Pipeline / Retag skipped Staging Worker Image (push) Failing after 26h19m46s
fix(#1834): 批量修复 UP 系列静态分析警告(UP007/UP006/UP017/UP035) (#1928)
Co-authored-by: xiaoxia <dev@xiaoxiajianji.com>
Co-committed-by: xiaoxia <dev@xiaoxiajianji.com>
2026-09-15 12:59:17 +08:00

145 lines
5.1 KiB
Python
Executable File

"""EditPlan domain entity for Phase 8 模板编排引擎."""
from __future__ import annotations
import sys
from dataclasses import dataclass, field
from datetime import UTC, datetime
if sys.version_info >= (3, 11):
from enum import StrEnum
else:
from enum import Enum
class StrEnum(str, Enum):
pass
from typing import Any
from uuid import uuid4
class EditPlanStatus(StrEnum):
"""剪辑计划状态"""
DRAFT = "draft"
EDITING = "editing"
RENDERING = "rendering"
COMPLETED = "completed"
FAILED = "failed"
@classmethod
def _missing_(cls, value: object) -> "EditPlanStatus":
"""兼容历史脏数据,避免枚举转换失败导致500。
- success/done/finished/complete → COMPLETED
- fail/error/err → FAILED
- render/rendering → RENDERING
- edit/editing → EDITING
- 其他未知值 → DRAFT(兜底,不阻塞业务)
"""
if isinstance(value, str):
normalized = value.strip().lower()
if normalized in ("done", "success", "finished", "complete", "completed"):
return cls.COMPLETED
if normalized in ("fail", "failed", "error", "err"):
return cls.FAILED
if normalized in ("render", "rendering", "generating", "generating_video"):
return cls.RENDERING
if normalized in ("edit", "editing", "working"):
return cls.EDITING
return cls.DRAFT
@dataclass(slots=True)
class EditPlan:
"""Phase 8 剪辑计划实体
基于某个 EditTemplate 创建的剪辑计划,包含具体的配置和状态追踪。
状态流转:draft → editing → rendering → completed / failed
"""
id: str
template_id: str
name: str
status: EditPlanStatus = EditPlanStatus.DRAFT
total_duration: float = 0.0
source_edit_plan_id: str = ""
project_id: str = ""
created_by_user_id: str = ""
config: dict[str, Any] = field(default_factory=dict)
created_at: datetime = field(default_factory=lambda: datetime.now(UTC))
updated_at: datetime = field(default_factory=lambda: datetime.now(UTC))
@classmethod
def create(
cls,
template_id: str,
name: str,
*,
config: dict[str, Any] | None = None,
total_duration: float = 0.0,
source_edit_plan_id: str = "",
project_id: str = "",
created_by_user_id: str = "",
) -> EditPlan:
"""创建新剪辑计划实例"""
clean_name = name.strip()
if not clean_name:
raise ValueError("计划名称不能为空")
if not template_id.strip():
raise ValueError("template_id 不能为空")
return cls(
id=uuid4().hex,
template_id=template_id.strip(),
name=clean_name,
status=EditPlanStatus.DRAFT,
total_duration=total_duration,
source_edit_plan_id=source_edit_plan_id.strip(),
project_id=project_id.strip(),
created_by_user_id=created_by_user_id.strip(),
config=config or {},
)
def start_editing(self) -> None:
"""开始编辑"""
if self.status != EditPlanStatus.DRAFT:
raise ValueError(f"只有 draft 状态的计划可以开始编辑,当前状态: {self.status}")
self.status = EditPlanStatus.EDITING
self.updated_at = datetime.now(UTC)
def start_rendering(self) -> None:
"""开始渲染"""
if self.status != EditPlanStatus.EDITING:
raise ValueError(f"只有 editing 状态的计划可以开始渲染,当前状态: {self.status}")
self.status = EditPlanStatus.RENDERING
self.updated_at = datetime.now(UTC)
def mark_completed(self) -> None:
"""标记为完成"""
if self.status != EditPlanStatus.RENDERING:
raise ValueError(f"只有 rendering 状态的计划可以标记完成,当前状态: {self.status}")
self.status = EditPlanStatus.COMPLETED
self.updated_at = datetime.now(UTC)
def mark_failed(self) -> None:
"""标记为失败"""
if self.status != EditPlanStatus.RENDERING:
raise ValueError(f"只有 rendering 状态的计划可以标记失败,当前状态: {self.status}")
self.status = EditPlanStatus.FAILED
self.updated_at = datetime.now(UTC)
def resume_editing(self) -> None:
"""重新进入编辑状态(完成/失败后重新编辑)"""
if self.status not in (EditPlanStatus.COMPLETED, EditPlanStatus.FAILED):
raise ValueError(f"只有 completed/failed 状态的计划可以重新编辑,当前状态: {self.status}")
self.status = EditPlanStatus.EDITING
self.updated_at = datetime.now(UTC)
def reset_to_draft(self) -> None:
"""重置为草稿状态(仅从 failed 状态可重置)"""
if self.status != EditPlanStatus.FAILED:
raise ValueError(f"只有 failed 状态的计划可以重置,当前状态: {self.status}")
self.status = EditPlanStatus.DRAFT
self.updated_at = datetime.now(UTC)