e83a0b86f8
CI/CD Pipeline / Check if frontend-only change (push) Has been skipped
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (push) Successful in 2s
CI/CD Pipeline / Check push changed paths (pull_request) Has been skipped
CI/CD Pipeline / PR Build Worker Image (push) Has been skipped
CI/CD Pipeline / PR Build Web Image (push) Has been skipped
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 2s
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (pull_request) Successful in 3s
CI/CD Pipeline / PR Build API Image (push) Has been skipped
CI/CD Pipeline / Frontend Lint (push) Has been skipped
CI/CD Pipeline / Validate - Style (pull_request) Has been skipped
CI/CD Pipeline / Validate - Security (pull_request) Has been skipped
CI/CD Pipeline / Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / Validate - Python (mypy + alembic) (pull_request) Has been skipped
CI/CD Pipeline / Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / Frontend Lint (pull_request) Has been skipped
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / Check push changed paths (push) Successful in 9s
CI/CD Pipeline / Retag skipped Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging Worker Image (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 / PR Build API Image (pull_request) Successful in 35s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 38s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (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 / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / Canary Release to Production (pull_request) Has been skipped
CI/CD Pipeline / Build Staging API Image (push) Successful in 58s
CI/CD Pipeline / Build Staging Worker Image (push) Successful in 55s
CI/CD Pipeline / Validate - Python (mypy + alembic) (push) Successful in 2m5s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 2m18s
CI/CD Pipeline / Validate - Style (push) Successful in 2m31s
CI/CD Pipeline / PR Build Web Image (pull_request) Successful in 2m30s
CI/CD Pipeline / Integration Tests (push) Successful in 2m35s
CI/CD Pipeline / CI Gate (pull_request) Successful in 1s
CI/CD Pipeline / Build Staging Web Image (push) Successful in 2m7s
CI/CD Pipeline / Retag skipped Staging API Image (push) Has been skipped
CI/CD Pipeline / Retag skipped Staging Worker Image (push) Has been skipped
CI/CD Pipeline / Retag skipped Staging Web Image (push) Has been skipped
PR Automation / Auto Approve on CI Green (pull_request) Successful in 3m15s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Successful in 1m30s
CI/CD Pipeline / Validate - Security (push) Successful in 4m34s
CI/CD Pipeline / ACR Image Cleanup (push) Successful in 1m37s
CI/CD Pipeline / Frontend Unit Tests (push) Successful in 5m54s
AI Code Review / AI Code Review (pull_request) Successful in 6m19s
CI/CD Pipeline / Staging API Integration Tests (push) Successful in 3m57s
CI/CD Pipeline / Unit Tests (push) Successful in 8m33s
CI/CD Pipeline / Build Production API Image (push) Has been skipped
CI/CD Pipeline / Build Production Web Image (push) Has been skipped
CI/CD Pipeline / Build Production Worker Image (push) Has been skipped
CI/CD Pipeline / CI Gate (push) Has been skipped
CI/CD Pipeline / Deploy Production (push) Has been skipped
CI/CD Pipeline / Production Browser E2E (push) Has been skipped
CI/CD Pipeline / Canary Release to Production (push) Has been skipped
CI/CD Pipeline / Staging E2E Tests (push) Failing after 4m48s
Co-authored-by: xiaoxia <dev@xiaoxiajianji.com> Co-committed-by: xiaoxia <dev@xiaoxiajianji.com>
142 lines
4.8 KiB
Python
Executable File
142 lines
4.8 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)
|
||
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
|
||
is_preview: bool = False
|
||
source_task_id: str = ""
|
||
output_width: int = 1280
|
||
output_height: int = 720
|
||
cover_url: str = ""
|
||
title_config: dict = field(default_factory=dict)
|
||
|
||
|
||
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=[], # #1749:voice_ids 已废弃(冗余 voice_library_id),DB 列保留只读
|
||
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,
|
||
is_preview=command.is_preview,
|
||
source_task_id=command.source_task_id,
|
||
output_width=command.output_width,
|
||
output_height=command.output_height,
|
||
cover_url=command.cover_url,
|
||
title_config=command.title_config,
|
||
)
|
||
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
|