efe7f6b52a
feat: 任务队列限流防护 - 用户级 pending 限流(3 个上限,返回 429) - 全局队列保护(20 个上限,返回 503) - 4 处入口全覆盖:批量创建、generation 重试、任务中心两级重试 - 入队前预检查 + 入队后最终校验双层兜底,处理并发竞态 - 阈值统一常量管理,边界语义一致 - 350+ 行单元测试覆盖所有边界场景
28 lines
838 B
Python
Executable File
28 lines
838 B
Python
Executable File
from __future__ import annotations
|
|
|
|
from typing import Protocol
|
|
|
|
from packages.domain import GenerationTask
|
|
|
|
|
|
class GenerationTaskRepository(Protocol):
|
|
def create(self, task: GenerationTask) -> GenerationTask: ...
|
|
|
|
def get(self, task_id: str) -> GenerationTask | None: ...
|
|
|
|
def list_by_project(self, project_id: str) -> list[GenerationTask]: ...
|
|
|
|
def list_by_user(self, user_id: str) -> list[GenerationTask]: ...
|
|
|
|
def count_by_user(self, user_id: str) -> int: ...
|
|
|
|
def count_pending_by_user(self, user_id: str) -> int: ...
|
|
|
|
def count_pending_total(self) -> int: ...
|
|
|
|
def list_recent_by_user(self, user_id: str, limit: int = 5) -> list[GenerationTask]: ...
|
|
|
|
def list_by_source_edit_plan(self, plan_id: str) -> list[GenerationTask]: ...
|
|
|
|
def update(self, task: GenerationTask) -> GenerationTask: ...
|