mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-04 23:17:20 +08:00
refactor(workflow): isolate legacy execution writes
This commit is contained in:
@@ -12,8 +12,10 @@ from typing import Any, Optional
|
||||
|
||||
from app.application.transfer.execution import TransferExecutionRepository
|
||||
from app.application.transfer.workflow import TransferAdmissionRepository
|
||||
from app.application.workflow import WorkflowExecutionPort
|
||||
|
||||
OperFactory = Callable[[], Any]
|
||||
WorkflowExecutionPortFactory = Callable[[], WorkflowExecutionPort]
|
||||
TransferAdmissionRepositoryFactory = Callable[[], TransferAdmissionRepository]
|
||||
TransferExecutionRepositoryFactory = Callable[[], TransferExecutionRepository]
|
||||
|
||||
@@ -24,7 +26,7 @@ class ChainDataPorts:
|
||||
|
||||
site: OperFactory
|
||||
subscribe: OperFactory
|
||||
workflow: OperFactory
|
||||
workflow: WorkflowExecutionPortFactory
|
||||
download_history: OperFactory
|
||||
transfer_history: OperFactory
|
||||
transfer_pending: TransferAdmissionRepositoryFactory
|
||||
@@ -103,25 +105,33 @@ class UserPortProxy(_ChainDataPortProxy):
|
||||
_ports: Optional[ChainDataPorts] = None
|
||||
|
||||
|
||||
def configure_chain_data_ports(**factories: OperFactory) -> None:
|
||||
"""由启动组合根登记 Chain 的数据端口实现。"""
|
||||
required = {
|
||||
"site",
|
||||
"subscribe",
|
||||
"workflow",
|
||||
"download_history",
|
||||
"transfer_history",
|
||||
"transfer_pending",
|
||||
"transfer_execution",
|
||||
"media_server",
|
||||
"download_failure",
|
||||
"user",
|
||||
}
|
||||
missing = sorted(required - factories.keys())
|
||||
if missing:
|
||||
raise ValueError(f"Chain 数据端口缺少实现: {', '.join(missing)}")
|
||||
def configure_chain_data_ports(
|
||||
*,
|
||||
site: OperFactory,
|
||||
subscribe: OperFactory,
|
||||
workflow: WorkflowExecutionPortFactory,
|
||||
download_history: OperFactory,
|
||||
transfer_history: OperFactory,
|
||||
transfer_pending: TransferAdmissionRepositoryFactory,
|
||||
transfer_execution: TransferExecutionRepositoryFactory,
|
||||
media_server: OperFactory,
|
||||
download_failure: OperFactory,
|
||||
user: OperFactory,
|
||||
) -> None:
|
||||
"""由启动组合根登记显式命名的 Chain 数据端口实现。"""
|
||||
global _ports
|
||||
_ports = ChainDataPorts(**{name: factories[name] for name in required})
|
||||
_ports = ChainDataPorts(
|
||||
site=site,
|
||||
subscribe=subscribe,
|
||||
workflow=workflow,
|
||||
download_history=download_history,
|
||||
transfer_history=transfer_history,
|
||||
transfer_pending=transfer_pending,
|
||||
transfer_execution=transfer_execution,
|
||||
media_server=media_server,
|
||||
download_failure=download_failure,
|
||||
user=user,
|
||||
)
|
||||
|
||||
|
||||
def get_chain_data_ports() -> ChainDataPorts:
|
||||
@@ -141,8 +151,8 @@ def get_chain_subscribe_port() -> Any:
|
||||
return get_chain_data_ports().subscribe()
|
||||
|
||||
|
||||
def get_chain_workflow_port() -> Any:
|
||||
"""创建工作流数据端口实例。"""
|
||||
def get_chain_workflow_port() -> WorkflowExecutionPort:
|
||||
"""返回类型化的工作流执行状态事务端口。"""
|
||||
return get_chain_data_ports().workflow()
|
||||
|
||||
|
||||
|
||||
@@ -240,6 +240,56 @@ class UnitOfWork(Protocol):
|
||||
...
|
||||
|
||||
|
||||
class WorkflowExecutionPort(Protocol):
|
||||
"""工作流 Chain 提交执行状态所需的类型化事务端口。"""
|
||||
|
||||
def start(self, workflow_id: int) -> bool:
|
||||
"""提交工作流运行中状态。"""
|
||||
...
|
||||
|
||||
def success(
|
||||
self,
|
||||
workflow_id: int,
|
||||
result: Optional[str] = None,
|
||||
) -> bool:
|
||||
"""提交工作流成功状态。"""
|
||||
...
|
||||
|
||||
def fail(self, workflow_id: int, result: str) -> bool:
|
||||
"""提交工作流失败状态。"""
|
||||
...
|
||||
|
||||
def step(
|
||||
self,
|
||||
workflow_id: int,
|
||||
action_id: str,
|
||||
context: dict[str, Any],
|
||||
execution_state: Optional[dict[str, Any]] = None,
|
||||
) -> bool:
|
||||
"""提交工作流动作进度。"""
|
||||
...
|
||||
|
||||
def reset(self, workflow_id: int, reset_count: bool = False) -> bool:
|
||||
"""提交工作流执行状态重置。"""
|
||||
...
|
||||
|
||||
|
||||
_configured_workflow_execution: Optional[WorkflowExecutionPort] = None
|
||||
|
||||
|
||||
def configure_workflow_execution(service: WorkflowExecutionPort) -> None:
|
||||
"""由启动组合根登记唯一工作流执行状态事务服务。"""
|
||||
global _configured_workflow_execution
|
||||
_configured_workflow_execution = service
|
||||
|
||||
|
||||
def get_configured_workflow_execution() -> WorkflowExecutionPort:
|
||||
"""返回启动阶段登记的工作流执行状态事务服务。"""
|
||||
if _configured_workflow_execution is None:
|
||||
raise RuntimeError("工作流执行状态事务服务尚未配置")
|
||||
return _configured_workflow_execution
|
||||
|
||||
|
||||
class WorkflowExecutionRepository(Protocol):
|
||||
"""工作流执行状态写入所需的最小暂存端口。"""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user