feat: complete production workflow migration
This commit is contained in:
1 parent
7f215e79c4
commit
8df5266abb
448 files changed
+56937
-14619
No files matched your search
@@ -3,9 +3,10 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import heapq
|
||||
import math
|
||||
import re
|
||||
from dataclasses import dataclass
|
||||
from typing import TYPE_CHECKING, Protocol
|
||||
from typing import TYPE_CHECKING, Literal, Protocol
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from gyxx_flow.core.context import RunContext
|
||||
@@ -15,6 +16,7 @@ if TYPE_CHECKING:
|
||||
|
||||
_ID = re.compile(r"^[a-z][a-z0-9]*(?:[._-][a-z0-9]+)*$")
|
||||
_RESOURCE = re.compile(r"^[A-Za-z0-9][A-Za-z0-9:._-]*$")
|
||||
ReplayPolicy = Literal["guarded", "idempotent"]
|
||||
|
||||
|
||||
class WorkflowValidationError(ValueError):
|
||||
@@ -47,6 +49,8 @@ class StepDefinition:
|
||||
resources: tuple[str, ...] = ()
|
||||
production_sink: bool = False
|
||||
official_notification: bool = False
|
||||
replay_policy: ReplayPolicy = "guarded"
|
||||
run_after_failure: bool = False
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
object.__setattr__(self, "depends_on", tuple(self.depends_on))
|
||||
@@ -65,7 +69,10 @@ class StepDefinition:
|
||||
if dependency == self.step_id:
|
||||
raise WorkflowValidationError(f"step {self.step_id!r} depends on itself")
|
||||
if self.timeout_seconds is not None and (
|
||||
isinstance(self.timeout_seconds, bool) or self.timeout_seconds <= 0
|
||||
isinstance(self.timeout_seconds, bool)
|
||||
or not isinstance(self.timeout_seconds, (int, float))
|
||||
or not math.isfinite(self.timeout_seconds)
|
||||
or self.timeout_seconds <= 0
|
||||
):
|
||||
raise WorkflowValidationError(
|
||||
f"timeout_seconds must be positive for step {self.step_id!r}"
|
||||
@@ -89,6 +96,20 @@ class StepDefinition:
|
||||
raise WorkflowValidationError(
|
||||
f"invalid resource for step {self.step_id!r}: {resource!r}"
|
||||
)
|
||||
if not isinstance(self.run_after_failure, bool):
|
||||
raise WorkflowValidationError(
|
||||
f"run_after_failure must be boolean for step {self.step_id!r}"
|
||||
)
|
||||
if self.replay_policy not in {"guarded", "idempotent"}:
|
||||
raise WorkflowValidationError(
|
||||
f"invalid replay_policy for step {self.step_id!r}: "
|
||||
f"{self.replay_policy!r}"
|
||||
)
|
||||
if self.replay_policy == "idempotent" and not self.production_sink:
|
||||
raise WorkflowValidationError(
|
||||
f"idempotent replay_policy requires production_sink for step "
|
||||
f"{self.step_id!r}"
|
||||
)
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
|
||||
Reference in new issue
Block a user