feat: 保存并登记当前 Client (#11)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
"""Client 访问 Admin 的稳定边界和简单数据对象。
|
||||
|
||||
AdminGateway 只有领取任务、提交成功结果、提交失败结果三个业务方法。
|
||||
AdminGateway 只有登记、领取任务、提交成功结果、提交失败结果四个业务方法。
|
||||
业务层不应直接依赖 HTTP 请求或 Mock 的内部实现。
|
||||
"""
|
||||
|
||||
@@ -13,13 +13,16 @@ from .task_models import TaskType
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class ClientInfo:
|
||||
"""发起领取请求的 Client 身份,不保存访问令牌。"""
|
||||
"""Client 身份和可选名称,不保存访问令牌。"""
|
||||
|
||||
client_id: str
|
||||
name: str = ""
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
if not self.client_id.strip():
|
||||
raise ValueError("client_id 不能为空")
|
||||
if len(self.name.strip()) > 50:
|
||||
raise ValueError("client.name 最多 50 个字")
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
@@ -43,7 +46,7 @@ class AndroidDeviceInfo:
|
||||
class ClaimCapabilities:
|
||||
"""Client 领取任务时声明的设备与执行能力。"""
|
||||
|
||||
device: AndroidDeviceInfo
|
||||
device: Optional[AndroidDeviceInfo] = None
|
||||
supported_types: Tuple[TaskType, ...] = (
|
||||
TaskType.COLLECT,
|
||||
TaskType.PURCHASE,
|
||||
@@ -96,6 +99,15 @@ class SubmissionReceipt:
|
||||
accepted_at: str
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class RegistrationReceipt:
|
||||
"""Admin 已登记当前 Client 的确认。"""
|
||||
|
||||
registered: bool
|
||||
client_id: str
|
||||
registered_at: str
|
||||
|
||||
|
||||
class AdminGatewayError(RuntimeError):
|
||||
"""带稳定错误代码和可重试标志的 Admin 边界错误。"""
|
||||
|
||||
@@ -114,8 +126,18 @@ class AdminGatewayError(RuntimeError):
|
||||
self.details = dict(details or {})
|
||||
|
||||
|
||||
class AdminGateway(ABC):
|
||||
"""Admin 边界;不得增加状态查询、心跳或租约方法。"""
|
||||
class ClientRegistrationGateway(ABC):
|
||||
"""设置页只依赖登记能力,不依赖任务领取和提交。"""
|
||||
|
||||
@abstractmethod
|
||||
def register_client(
|
||||
self, client: ClientInfo, capabilities: ClaimCapabilities
|
||||
) -> RegistrationReceipt:
|
||||
"""幂等登记或更新当前 Client。"""
|
||||
|
||||
|
||||
class AdminGateway(ClientRegistrationGateway):
|
||||
"""完整 Admin 边界;不得增加状态查询、心跳或租约方法。"""
|
||||
|
||||
@abstractmethod
|
||||
def claim_next(
|
||||
|
||||
Reference in New Issue
Block a user