Перенес workflow
This commit is contained in:
1
src/app_runtime/workflow/contracts/__init__.py
Normal file
1
src/app_runtime/workflow/contracts/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
__all__: list[str] = []
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
16
src/app_runtime/workflow/contracts/context.py
Normal file
16
src/app_runtime/workflow/contracts/context.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Any
|
||||
|
||||
|
||||
@dataclass(slots=True)
|
||||
class WorkflowContext:
|
||||
payload: dict[str, Any]
|
||||
state: dict[str, Any] = field(default_factory=dict)
|
||||
|
||||
def snapshot(self) -> dict[str, Any]:
|
||||
return {
|
||||
"payload": dict(self.payload),
|
||||
"state": dict(self.state),
|
||||
}
|
||||
11
src/app_runtime/workflow/contracts/result.py
Normal file
11
src/app_runtime/workflow/contracts/result.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Any
|
||||
|
||||
|
||||
@dataclass(slots=True)
|
||||
class StepResult:
|
||||
transition: str = "success"
|
||||
updates: dict[str, Any] = field(default_factory=dict)
|
||||
status: str = "completed"
|
||||
12
src/app_runtime/workflow/contracts/step.py
Normal file
12
src/app_runtime/workflow/contracts/step.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
from app_runtime.workflow.contracts.context import WorkflowContext
|
||||
from app_runtime.workflow.contracts.result import StepResult
|
||||
|
||||
|
||||
class WorkflowStep(ABC):
|
||||
@abstractmethod
|
||||
def run(self, context: WorkflowContext) -> StepResult:
|
||||
"""Run the step and return transition metadata."""
|
||||
19
src/app_runtime/workflow/contracts/workflow.py
Normal file
19
src/app_runtime/workflow/contracts/workflow.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
|
||||
from app_runtime.workflow.contracts.step import WorkflowStep
|
||||
|
||||
|
||||
@dataclass(slots=True)
|
||||
class WorkflowNode:
|
||||
name: str
|
||||
step: WorkflowStep
|
||||
transitions: dict[str, str] = field(default_factory=dict)
|
||||
|
||||
|
||||
@dataclass(slots=True)
|
||||
class WorkflowDefinition:
|
||||
name: str
|
||||
start_at: str
|
||||
nodes: dict[str, WorkflowNode]
|
||||
Reference in New Issue
Block a user