a9896e1507
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 21s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 37s
CI/CD Pipeline / PR Build Web Image (pull_request) Successful in 25s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 1m21s
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 1m23s
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Validate - Code Quality (pull_request) Failing after 1m55s
Preview Deploy / Deploy Preview Environment (pull_request) Failing after 23s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 59s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 53s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / Build Production API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 4m34s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 2m40s
AI Code Review / AI Code Review (pull_request) Successful in 4m4s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 5m49s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 10m3s
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 19s
- 领域模型 GenerationTask 新增 bgm_config 字段 - ORM/Repository/UseCase/API 全链路透传 bgm_config - Worker 端新增 BGM 配置合并逻辑(用户配置 > 模板配置) - enabled 字段特殊处理:用户显式传才覆盖模板状态 - 合并逻辑抽至 packages/domain/bgm_utils.py 纯函数 - 14个BGM合并单测 + 2个领域单测,全量4246通过
131 lines
4.4 KiB
Python
Executable File
131 lines
4.4 KiB
Python
Executable File
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass, field
|
|
from uuid import uuid4
|
|
|
|
from packages.domain import GenerationTask
|
|
from packages.ports.generation_task_repository import GenerationTaskRepository
|
|
|
|
|
|
@dataclass(slots=True)
|
|
class CreateGenerationTaskCommand:
|
|
project_id: str = ""
|
|
asset_library_id: str = ""
|
|
strategy_id: str = ""
|
|
voice_library_id: str = ""
|
|
template_id: str = ""
|
|
asset_ids: list[str] = field(default_factory=list)
|
|
title_ids: list[str] = field(default_factory=list)
|
|
voice_ids: list[str] = field(default_factory=list)
|
|
created_by_user_id: str = ""
|
|
source_edit_plan_id: str = ""
|
|
asset_select_mode: str = ""
|
|
batch_id: str = ""
|
|
video_title: str = ""
|
|
resolution: str = ""
|
|
bgm_config: dict = field(default_factory=dict)
|
|
auto_retry_enabled: bool = False
|
|
auto_retry_max: int = 0
|
|
|
|
|
|
class CreateGenerationTaskUseCase:
|
|
def __init__(self, generation_task_repository: GenerationTaskRepository):
|
|
self.generation_task_repository = generation_task_repository
|
|
|
|
def execute(self, command: CreateGenerationTaskCommand) -> GenerationTask:
|
|
task = GenerationTask(
|
|
id=uuid4().hex,
|
|
project_id=command.project_id,
|
|
asset_library_id=command.asset_library_id,
|
|
strategy_id=command.strategy_id,
|
|
voice_library_id=command.voice_library_id,
|
|
template_id=command.template_id,
|
|
asset_ids=command.asset_ids,
|
|
title_ids=command.title_ids,
|
|
voice_ids=command.voice_ids,
|
|
status="pending", # type: ignore[arg-type]
|
|
progress=0.0,
|
|
result_count=0,
|
|
error_message="",
|
|
created_by_user_id=command.created_by_user_id,
|
|
source_edit_plan_id=command.source_edit_plan_id,
|
|
asset_select_mode=command.asset_select_mode,
|
|
batch_id=command.batch_id,
|
|
video_title=command.video_title,
|
|
resolution=command.resolution,
|
|
bgm_config=command.bgm_config,
|
|
auto_retry_enabled=command.auto_retry_enabled,
|
|
auto_retry_max=command.auto_retry_max,
|
|
)
|
|
return self.generation_task_repository.create(task)
|
|
|
|
|
|
class GetGenerationTaskUseCase:
|
|
def __init__(self, generation_task_repository: GenerationTaskRepository):
|
|
self.generation_task_repository = generation_task_repository
|
|
|
|
def execute(self, task_id: str) -> GenerationTask | None:
|
|
return self.generation_task_repository.get(task_id)
|
|
|
|
|
|
@dataclass(slots=True)
|
|
class ListTasksFilter:
|
|
"""任务列表筛选条件。"""
|
|
|
|
status: str | None = None # pending, running, completed, failed, cancelled
|
|
|
|
|
|
@dataclass(slots=True)
|
|
class ListGenerationTasksResult:
|
|
"""带筛选和分页的任务列表结果。"""
|
|
|
|
items: list[GenerationTask]
|
|
total: int
|
|
|
|
|
|
class ListUserTasksFilteredUseCase:
|
|
"""按用户+筛选条件查询任务列表。"""
|
|
|
|
def __init__(self, generation_task_repository: GenerationTaskRepository):
|
|
self.generation_task_repository = generation_task_repository
|
|
|
|
def execute(
|
|
self,
|
|
user_id: str,
|
|
*,
|
|
status: str | None = None,
|
|
limit: int | None = None,
|
|
offset: int = 0,
|
|
) -> ListGenerationTasksResult:
|
|
items = self.generation_task_repository.list_by_user_filtered(
|
|
user_id,
|
|
status=status,
|
|
limit=limit,
|
|
offset=offset,
|
|
)
|
|
total = self.generation_task_repository.count_by_user_filtered(
|
|
user_id,
|
|
status=status,
|
|
)
|
|
return ListGenerationTasksResult(items=items, total=total)
|
|
|
|
|
|
class RetryGenerationTaskUseCase:
|
|
"""原地重试失败的任务(重置状态+递增retry_count)。
|
|
|
|
与创建新任务不同:复用同一个 task_id,保留历史关联。
|
|
"""
|
|
|
|
def __init__(self, generation_task_repository: GenerationTaskRepository):
|
|
self.generation_task_repository = generation_task_repository
|
|
|
|
def execute(self, task_id: str) -> GenerationTask:
|
|
task = self.generation_task_repository.get(task_id)
|
|
if task is None:
|
|
raise ValueError(f"任务不存在: {task_id}")
|
|
if not task.is_failed:
|
|
raise ValueError(f"只有失败状态的任务才能重试,当前状态: {task.status.value}")
|
|
task.mark_pending_from_failed()
|
|
self.generation_task_repository.update(task)
|
|
return task
|